Skip to content

python.sqlalchemy.query_timeout

Stability High

Detects SQLAlchemy queries without timeout configuration.

Queries without timeout:

  • Connection pool exhaustion — Slow queries hold connections
  • Cascading failures — One slow query blocks others
  • Resource starvation — Workers stuck waiting
# ❌ Before (no timeout)
result = session.execute(text("SELECT * FROM large_table"))
# ✅ After (with timeout)
from sqlalchemy import text
# Set statement timeout per query
result = session.execute(
text("SELECT * FROM large_table"),
execution_options={"timeout": 30}
)
# Or set globally on engine
engine = create_engine(
'postgresql://...',
connect_args={"options": "-c statement_timeout=30000"}
)
  • Queries without timeout configuration
  • Missing statement_timeout at engine level
  • Long-running queries without guards