Repository navigation
Unexpected argument(s) warning in PyCharm when using select() with many parameters #92
Description
Activity
- addedquestionFurther information is requestedFurther information is requested
on Sep 12, 2021 - changed the title
[-]"Unexpected argument(s)" warning in PyCharm when using select() with many parameters [/-][+]`Unexpected argument(s)` warning in PyCharm when using `select()` with many parameters [/+]on Sep 12, 2021 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_typefromtyping_extensionsI 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
selectfromsqlalchemyinstead 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:
- Use sqlalchemy's select when using more then 4 parameters for select
- Add more hardcoded overloads for more parameters, which I guess will grow the amount of overloads exponentially because of the different combinations of
_TScalar_XandType[_TModel_X]for each parameter. - Find a dynamic solution if there is any
Same issue here
Reacted by chi11ax@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 !!
Reacted by Marcos A. Sobrinho, Tomas Lapes, Vinicius Abade and Or GanyI think this is the same as #271
Let's close this and track it here


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