From d6504fe176599da826324f5b0bc959201924fd24 Mon Sep 17 00:00:00 2001 From: Marti Raudsepp Date: Tue, 1 Mar 2022 17:21:06 +0200 Subject: [PATCH] Remove hard dependency on psycopg2 One would reasonably expect django-celery-results to work with other databases without installing psycopg2. The hard dependency was added in commit 28fb1c64fd44684d16b69d15083a01cb9047d3d8, probably unintentional without fully understanding this aspect. --- django_celery_results/backends/database.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/django_celery_results/backends/database.py b/django_celery_results/backends/database.py index 6ef548f5..1d7e0043 100644 --- a/django_celery_results/backends/database.py +++ b/django_celery_results/backends/database.py @@ -10,13 +10,18 @@ from django.db import connection, transaction from django.db.utils import InterfaceError from kombu.exceptions import DecodeError -from psycopg2 import InterfaceError as Psycopg2InterfaceError from ..models import ChordCounter from ..models import GroupResult as GroupResultModel from ..models import TaskResult -EXCEPTIONS_TO_CATCH = (InterfaceError, Psycopg2InterfaceError) +EXCEPTIONS_TO_CATCH = (InterfaceError,) + +try: + from psycopg2 import InterfaceError as Psycopg2InterfaceError + EXCEPTIONS_TO_CATCH += (Psycopg2InterfaceError,) +except ImportError: + pass logger = get_logger(__name__)