SESS002errorFree tier

thread-session-safety

SQLAlchemy session used across ThreadPoolExecutor boundary.

Applies to: Python

Why this matters

SQLAlchemy sessions are NOT thread-safe. When a function submitted to ThreadPoolExecutor calls session.commit(), execute(), or similar methods, it races with the main thread's session usage, corrupting transaction state. This causes 'prepared state' errors, lost data, and cascading failures. Worker threads should only do I/O; all DB writes belong on the main thread.

Catch it before it ships

pip install stablestack # or: npx stablestackstablestack # scans your project, SESS002 includedstablestack explain SESS002

False positive in your codebase? Suppress a single line with # noqa: SESS002