I used the GitHub search to find a similar issue and didn't find it.
I searched the SQLModel documentation, with the integrated search.
I already searched in Google "How to X in SQLModel" and didn't find any information.
I already read and followed all the tutorial in the docs and didn't find an answer.
I already checked if it is not related to SQLModel but to Pydantic.
I already checked if it is not related to SQLModel but to SQLAlchemy.
Commit to Help
I commit to help with one of those options 👆
Example Code
fromtypingimportOptionalfromdatetimeimportdatetimefromsqlmodelimportField, SQLModel, select, func, create_engine, SessionclassItem(SQLModel, table=True):
id: Optional[int] =Field(default=None, primary_key=True)
created: datetimedeleted: bool=Falsecategory: strversion: float=1data: str# Create and save records to show that the query itself is working.item_1=Item(created=datetime.now(), category="category_1", data="❤️ I love SQLModel.")
item_2=Item(created=datetime.now(), category="category_1", data="❤️ I love FastAPI.", deleted=True)
item_3=Item(created=datetime.now(), category="category_2", data="🥰 I appreciate your work on all of it!")
engine=create_engine("sqlite://")
SQLModel.metadata.create_all(engine)
withSession(engine) assession:
session.add(item_1)
session.add(item_2)
session.add(item_3)
session.commit()
# This "statement" is where the issue presents itself in PyCharmstatement= (
select(
Item.category,
func.count(Item.id),
func.total(Item.deleted).label("delete_count"),
func.min(Item.created).label("oldest_timestamp"),
func.max(Item.created).label("newest_timestamp"),
func.group_concat(Item.version).label("version_list"),
)
.distinct()
.group_by(Item.category)
)
category_metadata=session.exec(statement)
forresultincategory_metadata:
print(dict(result))
Description
Using the select() function to write out a query with > 4 params.
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 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.
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_X and Type[_TModel_X] for each parameter.
@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 Gany
Activity
Cielquan commented on May 6, 2022
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.
And when I use reveal_type from typing_extensions I get this:
When I reduce the arguments to select I get:
When I use select from sqlalchemy instead it works with all arguments and I get:
Cielquan commented on May 6, 2022
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:
kiddten commented on Jun 22, 2022
Same issue here
etash47 commented on Jun 22, 2024
@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 !!
1990heidou commented on Sep 26, 2024
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:

YuriiMotov commented on Aug 27, 2025
I think this is the same as #271
Let's close this and track it here