Skip to content

PY-SQLA0003 · sqlmodel_execute_scalars_api

Prefer SQLModel exec for exact scalar selections.

This is a deterministic rule for python. Read its implementation.

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.

Each finding points to one complete execute(...).scalars() chain. The value is the number of exact chains.

Raw SQLAlchemy sessions, multi-expression selects, textual SQL, execution options, statement variables, and row-shaped results remain unreported. SQLAlchemy owns those general cases.

heroes = session.execute(select(Hero)).scalars().all()
heroes = session.exec(select(Hero)).all()
  • Cites “SQLModel documentation”, selection technical details. Open reference
  • Cites “SQLAlchemy documentation”, scalar-result guidance. Open reference