-
-
Notifications
You must be signed in to change notification settings - Fork 782
✨ Add PEP 593 support for Requirement annotations #1192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
YuriiMotov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bolu61, thanks for working on this!
So, this PR fixes the following code example:
class Foo(SQLModel, table=True):
id: Annotated[int | None, Field(primary_key=True)] = None
uuid: Annotated[UUID, Field(unique=True)]
class Bar(SQLModel, table=True):
id: Annotated[int | None, Field(primary_key=True)] = None
uuid: Annotated[UUID, Field(unique=True)]
foo_id: Annotated[int, Field(foreign_key="foo.id")]
foo: Annotated[Foo, Relationship()]For now last line (with Relationship()) doesn't work (ValueError: <class '__main__.Foo'> has no matching SQLAlchemy type) and this PR fixes that.
I think this is not the same that was initially proposed in #229. The idea there was to support passing multiple annotations like:
class Hero(SQLModel, table=True):
id: Annotated[Optional[int], Field(examples=....), Column(primary_key=True)] = NoneWhere Field can be pydantic.Field.
So, I suggest we unmark this PR as the one that resolves that issue.
As for changes introduced by this PR, I think it goes in line with modern recommendations to use Annotated approach instead parameterizing fields via default value.
I think we should test this approach more and add some automatic tests. Then it will have all chances to be accepted.
|
@YuriiMotov I agree. I'm not too familiar with this codebase. Can you point me to where I can write those tests? |
You can create an annotated version of the code example from "Relationships" section of docs:
|
|
Heads-up: this will be closed in 3 days unless there’s new activity. |
|
The test is failing with: I'm not exactly sure how to approach this. |
📝 Docs previewLast commit 40af690 at: https://c0d7bffc.sqlmodel.pages.dev |
This is related to #1623 . I hope it will be fixed soon |
see #229 (comment)
I'm not really sure how Pydantic does it, but here's a potential workaround to the problem.