Skip to content

Commit 79bd164

Browse files
authored
Merge pull request #159 from jazzband/149-extra-psycopg2
#149 Added a clear message on ImportError when the psycopg2 package cannot be found.
2 parents 3697dfe + 75a5c4a commit 79bd164

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

CHANGES.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ CHANGES
44
4.2.0 (Unreleased)
55
------------------
66

7+
General:
8+
9+
* #149 Added a clear message on ImportError when the psycopg2
10+
package cannot be found.
11+
Please refer to the following site for more information:
12+
https://django-redshift-backend.readthedocs.io/en/master/basic.html#installation
13+
714
Features:
815

916
* #143 Add Django-5.0 support.

django_redshift_backend/base.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,18 @@
1515
import django
1616
from django.utils import timezone
1717
from django.conf import settings
18-
from django.core.exceptions import FieldDoesNotExist
18+
from django.core.exceptions import FieldDoesNotExist, ImproperlyConfigured
1919
from django.db.models import Index
2020
from django.db.models.expressions import Col
2121
from django.db.utils import NotSupportedError, ProgrammingError
2222

23+
try:
24+
from psycopg2.extensions import Binary
25+
except ImportError:
26+
raise ImproperlyConfigured(
27+
"Error loading psycopg2 module. Please install as: `pip install django-redshift-backend[psycopg2]` or `pip install django-redshift-backend[psycopg2-binary]`. For more information, see https://django-redshift-backend.readthedocs.io/en/master/basic.html#installation"
28+
)
29+
2330
from ._vendor.django40.db.backends.base.introspection import FieldInfo, TableInfo
2431
from ._vendor.django40.db.backends.base.schema import (
2532
_is_relevant_relation,
@@ -37,8 +44,6 @@
3744
DatabaseIntrospection as BasePGDatabaseIntrospection,
3845
)
3946
from .meta import DistKey, SortKey
40-
from psycopg2.extensions import Binary
41-
4247
from .psycopg2adapter import RedshiftBinary
4348

4449
logger = logging.getLogger("django.db.backends")

tox.ini

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,12 @@ DJANGO =
2828

2929
[testenv]
3030
deps =
31+
.[psycopg2-binary]
3132
coverage
32-
psycopg2-binary>=2.7
3333
pytest
3434
pytest-cov
3535
mock>=2.0
3636
django-environ
37-
py38: backports.zoneinfo
3837
dj32: Django>=3.2,<3.3
3938
dj40: Django>=4.0,<4.1
4039
dj42: Django>=4.2,<5.0

0 commit comments

Comments
 (0)