Enhancement: Ensure proper DB connection management in Celery tasks by checking for worker context before releasing connections, preventing potential ORM errors.

This commit is contained in:
SergeantPanda 2026-07-07 18:26:09 +00:00
parent 810a7a93a1
commit dff97d9067

View file

@ -36,6 +36,7 @@ from core.utils import (
send_websocket_update,
cleanup_memory,
log_system_event,
_is_celery_worker_context,
)
logger = logging.getLogger(__name__)
@ -100,6 +101,8 @@ _NON_TERMINAL_REFRESH_STATUSES = frozenset({
def _release_task_db_connection():
"""Return the Celery worker's DB connection to a clean state after ORM errors."""
if not _is_celery_worker_context():
return
from django.db import close_old_connections
close_old_connections()