PY-SQLA0004 · sqlmodel_redundant_scalars
Remove scalar extraction repeated after SQLModel exec.
This is a deterministic rule for python. Read its implementation.
Definition
Section titled “Definition”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.
Evidence
Section titled “Evidence”Each finding points to one redundant scalars call. The value is the number of exact chains.
Exceptions
Section titled “Exceptions”Multi-expression selects and unresolved sessions remain unreported because SQLModel preserves row-shaped results for those statements.
Examples
Section titled “Examples”heroes = session.exec(select(Hero)).scalars().all()heroes = session.exec(select(Hero)).all()References
Section titled “References”- Cites “SQLModel documentation”, selection technical details. Open reference
- Cites “SQLModel documentation”, compact selection example. Open reference