SQLModel col() has unresolved attribute issue and no autocompletion #1579
-
First Check
Commit to Help
Example Codefrom typing import Optional
from sqlmodel import Field, Session, SQLModel, create_engine, select, col
class Hero(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
name: str
secret_name: str
age: Optional[int] = None
hero_1 = Hero(name="Deadpond", secret_name="Dive Wilson")
engine = create_engine("sqlite:///database.db", echo=True)
SQLModel.metadata.create_all(engine)
with Session(engine) as session:
session.add(hero_1)
session.commit()
session.refresh(hero_1)
hero_names = [
"Beep",
"Boop",
"Deadpond",
"Zorf",
]
statement = select(Hero).where(col(Hero.name) == "Deadpond")
results = session.exec(statement)
for hero in results:
print(hero) DescriptionImporting and using the col() does not tell the editor (Pycharm in this case) that this class attribute is a SQLModel column. The code does work however. ![]() Operating SystemmacOS Operating System DetailsNo response SQLModel Version0.0.25 Python Version3.12 Additional ContextPycharm: 2025.2.2 |
Beta Was this translation helpful? Give feedback.
Answered by
YuriiMotov
Sep 27, 2025
Replies: 1 comment 3 replies
-
Isn't it the same issue as #115 ? |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
col
"fixes" the type of its argument (Hero.name
), but Pycharm argues on not seeingname
attribute inHero
class. Resolving this attribute access happens before passing it tocol
. So,col
can't fix it (and it's not its purpose).col
casts theHero.name
fromstr
type to column type.