Open avi-perl opened 3 years ago
I have the same issue.
I have a table with 5 foreign keys. And when I want to do a full join like below I get a mypy error. So I assume the typing is the issue here. And PyCharm uses the types too I think.
from sqlmodel import select
...
stmt = (
select(
Ticket, TicketStage, ConspicuityType, User, ATFeedbackType, StatisticalEvaluationType
)
.join(TicketStage)
.join(ConspicuityType)
.join(User)
.join(ATFeedbackType)
.join(StatisticalEvaluationType)
)
And when I use reveal_type
from typing_extensions
I get this:
from typing_extensions import reveal_type
from sqlmodel import select
...
stmt = (
select(
Ticket, TicketStage, ConspicuityType, User, ATFeedbackType, StatisticalEvaluationType
)
.join(TicketStage)
.join(ConspicuityType)
.join(User)
.join(ATFeedbackType)
.join(StatisticalEvaluationType)
)
reveal_type(stmt) # Type of "stmt" is "Any"
When I reduce the arguments to select I get:
from typing_extensions import reveal_type
from sqlmodel import select
...
stmt = (
select(
Ticket, TicketStage, ConspicuityType, User
)
.join(TicketStage)
.join(ConspicuityType)
.join(User)
.join(ATFeedbackType)
.join(StatisticalEvaluationType)
)
reveal_type(stmt) # Type of "stmt" is "Select[Tuple[Ticket, TicketStage, ConspicuityType, User]]"
When I use select
from sqlalchemy
instead it works with all arguments and I get:
from typing_extensions import reveal_type
from sqlalchemy import select
...
stmt = (
select(
Ticket, TicketStage, ConspicuityType, User, ATFeedbackType, StatisticalEvaluationType
)
.join(TicketStage)
.join(ConspicuityType)
.join(User)
.join(ATFeedbackType)
.join(StatisticalEvaluationType)
)
reveal_type(stmt) # Type of "stmt" is "Select"
Basically the issues lies here: https://github.com/tiangolo/sqlmodel/blob/main/sqlmodel/sql/expression.py#L140-L442
The overloads are hardcoded and end with 4 parameters. So I guess there are 3 Solutions:
_TScalar_X
and Type[_TModel_X]
for each parameter.Same issue here
@tiangolo we're still having this issue in a ton of places in our code base, any we can resolve or merge max's fix? Would be a huge QOL improvement for us. Thank you !!
Due to the fact that the 'select' parameter in the SQL model is as follows:
You can first create a list of parameters that need to be queried:
First Check
Commit to Help
Example Code
Description
select()
function to write out a query with > 4 params.select()
, the query works as expected.Operating System
Windows
Operating System Details
Windows = 10 PyCharm Version = 2021.2 (Community Edition)
SQLModel Version
0.0.4
Python Version
Python 3.9.7
Additional Context