SESS001errorPro

background-task-session

Database session passed to background task.

Applies to: Python

Why this matters

When you pass a database session to background_tasks.add_task(), the session gets closed when the request ends, but the background task hasn't run yet. This causes 'session is closed' errors and connection pool exhaustion. Create a new session inside the background task instead.

Catch it before it ships

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

SESS001 is part of the Pro rule set. See pricing — the free tier ships 24 checks with no signup.

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