Error initializing relations in mapper when compiled with Cython #771
Replies: 4 comments 4 replies
-
This seems to be a problem related to a new(er) release of sqlalchemy, But this still did not solve the problem for me. Looking for any help. |
Beta Was this translation helpful? Give feedback.
-
Same issue with cython and works well with cPython. any workaround here for this issue? |
Beta Was this translation helpful? Give feedback.
-
What helped in my case was supplying the from sqlalchemy.orm import Mapped, relationship
...
heroes: Mapped[list[Message]] = Relationship(sa_relationship=relationship(back_populates="team")) |
Beta Was this translation helpful? Give feedback.
-
I have come across this issue as well. Using Digging into the code, I think the type annotations are being saved in
This wouldn't work for the same reason as above. type annotations are probably coming in a strings. In my case, the annotations are saved in cls.annotations I think it makes sense for sqlmodel to understand the type annotations even if they come in as a string. For now, I removed the future import and everything works as expected. |
Beta Was this translation helpful? Give feedback.
-
First Check
Commit to Help
Example Code
Description
When compiling and running my SQLModel Code with Cython, I get the following error:
sqlalchemy.exc.InvalidRequestError: When initializing mapper Mapper[Document(documents)], expression "relationship("Optional['Collection']")" seems to be using a generic class as the argument to relationship(); please state the generic argument using an annotation, e.g. "collection: Mapped[Optional['Collection']] = relationship()"
Changing the code to the proposed
collection: Mapped[Optional['Collection']]
does not help.When using the code with the Python interpreter, it just works fine.
Operating System
Linux
Operating System Details
Running this code via the Devcontainer Extension of VSCode, which means I'm running it in Docker for Mac.
SQLModel Version
0.0.14
Python Version
3.11.7
Additional Context
Cython Version: 3.0.7
Beta Was this translation helpful? Give feedback.
All reactions