fix(tasks): use task_session() in all Celery task bodies (#129) #159
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/129-celery-task-session"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Celery spins up a fresh event loop per task invocation, so a pooled connection from the global
AsyncSessionLocalcan be reused under a different loop than it was created on, making asyncpg raiseFuture ... attached to a different loop. In production this presented as intermittent recap-email and vote-auto-close failures that cleared after a worker restart.app/database.pyalready providestask_session()— a throw-away NullPool engine per call — and most tasks use it. This sweeps the remaining offenders to use it too.Changes
AsyncSessionLocaluse inside a Celery task body totask_session()acrossapp/tasks/reminder_tasks.pyandapp/tasks/planning_tasks.py(7 + 1 sites). Both context managers have identical commit semantics (neither auto-commits), so it is a drop-in swap.tests/test_task_session_hygiene.py: a regression guard that fails ifAsyncSessionLocalis referenced anywhere underapp/tasks/.Verification
Closes #129
🤖 Generated with Claude Code