Skip to content

Question about splitting the sqlmodel model and causing circular references #942

Answered by imneedle
Cassianvale asked this question in Questions
Discussion options

You must be logged in to vote

This is in the documentation on splitting your code into multiple files.

You are doing the correct thing by type hinting with quotes inside your apps/item/model.py file:

    owner: Optional["User"] = Relationship(back_populates="items")

Since you are quoting your type hint, you don't need the import at that file when running it. However, it's nice to have the import to get the auto completion in your editor :)

This is what the documentation suggests, you should import TYPE_CHECKING from the typing module.

(Note: When you import conditionally from the TYPE_CHECKING variable, that is when it becomes important to quote your type hints)
From the documentation:
And of course, all the tricks w…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Cassianvale
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
2 participants