PY-SQLA0003 · sqlmodel_execute_scalars_api
Prefer SQLModel exec for exact scalar selections.
This is a deterministic rule for python. Read its implementation.
Definition
Section titled “Definition”Report session.execute(select(Item)).scalars() only when Session or AsyncSession and
select resolve to SQLModel imports. The direct single-expression form has the same scalar
result contract as SQLModel exec but bypasses SQLModel’s typed convenience API.
Evidence
Section titled “Evidence”Each finding points to one complete execute(...).scalars() chain. The value is the number of
exact chains.
Exceptions
Section titled “Exceptions”Raw SQLAlchemy sessions, multi-expression selects, textual SQL, execution options, statement variables, and row-shaped results remain unreported. SQLAlchemy owns those general cases.
Examples
Section titled “Examples”heroes = session.execute(select(Hero)).scalars().all()heroes = session.exec(select(Hero)).all()References
Section titled “References”- Cites “SQLModel documentation”, selection technical details. Open reference
- Cites “SQLAlchemy documentation”, scalar-result guidance. Open reference