FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

🐛 Fix type annotation in `Field` constructor by AlanBogarin · Pull Request #1304 · fastapi/sqlmodel · GitHub

Repository navigation

🐛 Fix type annotation in Field constructor - #1304

Merged
tiangolo merged 3 commits into
fastapi:mainfrom
AlanBogarin:main
Feb 28, 2025
Merged

tiangolo merged 3 commits into
fastapi:mainfrom
AlanBogarin:main

Conversation

Copy link
Copy Markdown
Contributor

Type checker throw partially unknown error when used in strict mode (Pylance)
When I locally edited that line, everything was correct

the Column type needs a type argument, assign it Any to accept all instances of the object

origin: sqlmodel.main.Field
info: Column expected an argument

339 |    sa_column: Union[Column, UndefinedType] = Undefined,  # type: ignore

proposed change

339 |    sa_column: Union[Column[Any], UndefinedType] = Undefined,

If you want to see it yourself (be sure to set the type checker to strict)

import sqlmodel

class TestModel(sqlmodel.SQLModel, table=True):
    value: list[int] = sqlmodel.Field(sa_column=sqlmodel.Column(sqlmodel.JSON))

There is a better change, but it is not possible because Column was defined in sqlalchemy

# sqlalchemy.sql.schema
113 |    _T = TypeVar("_T", bound="Any", default="Any")  # python >= 3.13

The `Column` annotation of `sa column` was missing an type argument
svlandeg added the bug Something isn't working label Feb 24, 2025
svlandeg changed the title Fix sqlmodel.Field partially unknown 🐛 Fix type annotation in Field constructor Feb 24, 2025

svlandeg left a comment •
edited
Loading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thanks for the contribution @AlanBogarin!

This looks good to me, but I'll leave the final review & decision up to Tiangolo.

tiangolo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Makes sense, thank you! ☕

tiangolo merged commit 7a51870 into fastapi:main Feb 28, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL