From bbd0cb25211e630be8a928db334e5e9f148eb79f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20C=2E=20Fernandes?= Date: Tue, 14 Apr 2026 13:20:23 +0100 Subject: [PATCH] packages/django-dramatiq-postgres: reset db connections in raise_connection_error (#21577) Co-authored-by: Marc 'risson' Schmitt --- .../django_dramatiq_postgres/broker.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/django-dramatiq-postgres/django_dramatiq_postgres/broker.py b/packages/django-dramatiq-postgres/django_dramatiq_postgres/broker.py index 459a266a27..07bde403cb 100644 --- a/packages/django-dramatiq-postgres/django_dramatiq_postgres/broker.py +++ b/packages/django-dramatiq-postgres/django_dramatiq_postgres/broker.py @@ -62,6 +62,10 @@ def raise_connection_error(func: Callable[P, R]) -> Callable[P, R]: # noqa: UP0 return func(*args, **kwargs) except DATABASE_ERRORS as exc: logger.warning("Database error encountered", exc=exc) + try: + connections.close_all() + except DATABASE_ERRORS: + pass raise ConnectionError(str(exc)) from exc # type: ignore[no-untyped-call] return wrapper