SQLModel unknown type as prop on BaseModel #822
Unanswered
EvanSchalton
asked this question in
Questions
Replies: 2 comments
-
I'm having the same issue. It breaks all type hints related to SQLModel classes in VS Code. |
Beta Was this translation helpful? Give feedback.
0 replies
-
This might also be relevant here. I experience the same issues when dealing with relationships and methods in a class Team(SQLModel):
id: Optional[int] = Field(default=None, primary_key=True)
name: str
heroes: List["Hero"] = Relationship(back_populates="team")
def team_power(self) -> str:
if self.heroes:
powers: List[str] = []
for hero in self.heroes:
powers.append(hero.power) # This works?
else:
powers = ["No powers"]
return f"Team has powers: {powers}"
class Hero(SQLModel):
id: Optional[int] = Field(default=None, primary_key=True)
team_id: Optional[int] = Field(default=None, foreign_key="team.id")
team: Team = Relationship(back_populates="heroes")
power: str
def hero_power(self) -> str:
if self.team is not None: # Type of "team" is unknown
team = self.team.name # Type of "team" is unknown
else:
team = "No team"
return f"Hero is in {team} and has {self.power}!" The strange thing is that it works for |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
First Check
Commit to Help
Example Code
Description
Operating System
Linux
Operating System Details
No response
SQLModel Version
0.0.16
Python Version
Python 3.11.8
Additional Context
Beta Was this translation helpful? Give feedback.
All reactions