You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I used the GitHub search to find a similar issue and didn't find it.
I searched the SQLModel documentation, with the integrated search.
I already searched in Google "How to X in SQLModel" and didn't find any information.
I already read and followed all the tutorial in the docs and didn't find an answer.
I already checked if it is not related to SQLModel but to Pydantic.
I already checked if it is not related to SQLModel but to SQLAlchemy.
Commit to Help
I commit to help with one of those options 👆
Example Code
fromsqlmodelimportRelationship, SQLModel, Fieldfrompydantic.mainimportBaseModelclassSpecialFieldValidator(BaseModel):
id: int=Field(primary_key=True, index=True)
def__init_subclass__(cls) ->None:
# Try to figure out what type the special_field relation hasprint("special_field"incls.__annotations__) # Falseprint("special_field"incls.__fields__) # Falseprint("special_field"incls.__sqlmodel_relationships__) # True, but no type info via this dict, just a plain RelationshipInfo() instance:print(dict(cls.__sqlmodel_relationships__["special_field"].__dict__)) # {'back_populates': None, 'link_model': None, 'sa_relationship': None, 'sa_relationship_args': None, 'sa_relationship_kwargs': None}returnsuper().__init_subclass__()
classMyModelA(SQLModel, SpecialFieldValidator, table=True):
id: int=Field(primary_key=True)
special_field_id: int=Field(foreign_key="mymodelb.id")
special_field: "MyModelB"=Relationship()
classMyModelB(SQLModel, SpecialFieldValidator, table=True):
id: int=Field(primary_key=True)
special_field_id: int=Field(foreign_key="mymodela.id")
special_field: MyModelA=Relationship()
Description
I'm trying to write a class (SpecialFieldValidator) that is supposed to check whether a specific field, which is always a Relationship, was annotated with a particular type.
However, the actual type annotation seems to be getting erased - looking in fields, annotations yields nothing, and the data in sqlmodel_relationships does not feature a type.
Operating System
Linux
Operating System Details
No response
SQLModel Version
0.0.8
Python Version
3.11.0
Additional Context
SQLAlchemy version is 1.4.41
I found this issue: #255 that seems related, saying SQLAlchemy 1.4.36 breaks relationship, but SQLModels dependencies were officially updated to >=1.4.41 more recently than that so I figured this is a new issue.
The text was updated successfully, but these errors were encountered:
First Check
Commit to Help
Example Code
Description
I'm trying to write a class (SpecialFieldValidator) that is supposed to check whether a specific field, which is always a Relationship, was annotated with a particular type.
However, the actual type annotation seems to be getting erased - looking in fields, annotations yields nothing, and the data in sqlmodel_relationships does not feature a type.
Operating System
Linux
Operating System Details
No response
SQLModel Version
0.0.8
Python Version
3.11.0
Additional Context
SQLAlchemy version is 1.4.41
I found this issue: #255 that seems related, saying SQLAlchemy 1.4.36 breaks relationship, but SQLModels dependencies were officially updated to >=1.4.41 more recently than that so I figured this is a new issue.
The text was updated successfully, but these errors were encountered: