Skip to content

PY-SQLA0004 · sqlmodel_redundant_scalars

Remove scalar extraction repeated after SQLModel exec.

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

Report session.exec(select(Item)).scalars() only when the session and select resolve to SQLModel and the select contains exactly one expression. SQLModel already applies scalar extraction for that statement shape.

Each finding points to one redundant scalars call. The value is the number of exact chains.

Multi-expression selects and unresolved sessions remain unreported because SQLModel preserves row-shaped results for those statements.

heroes = session.exec(select(Hero)).scalars().all()
heroes = session.exec(select(Hero)).all()
  • Cites “SQLModel documentation”, selection technical details. Open reference
  • Cites “SQLModel documentation”, compact selection example. Open reference