Skip to content

Commit 5f507c8

Browse files
intgrauvipy
authored andcommitted
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 28fb1c6, probably unintentional without fully understanding this aspect.
1 parent 9735e28 commit 5f507c8

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

django_celery_results/backends/database.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,18 @@
1010
from django.db import connection, transaction
1111
from django.db.utils import InterfaceError
1212
from kombu.exceptions import DecodeError
13-
from psycopg2 import InterfaceError as Psycopg2InterfaceError
1413

1514
from ..models import ChordCounter
1615
from ..models import GroupResult as GroupResultModel
1716
from ..models import TaskResult
1817

19-
EXCEPTIONS_TO_CATCH = (InterfaceError, Psycopg2InterfaceError)
18+
EXCEPTIONS_TO_CATCH = (InterfaceError,)
19+
20+
try:
21+
from psycopg2 import InterfaceError as Psycopg2InterfaceError
22+
EXCEPTIONS_TO_CATCH += (Psycopg2InterfaceError,)
23+
except ImportError:
24+
pass
2025

2126
logger = get_logger(__name__)
2227

0 commit comments

Comments
 (0)