Skip to content

Commit

Permalink
Merge pull request #159 from jazzband/149-extra-psycopg2
Browse files Browse the repository at this point in the history
#149 Added a clear message on ImportError when the psycopg2 package cannot be found.
  • Loading branch information
shimizukawa authored Oct 30, 2024
2 parents 3697dfe + 75a5c4a commit 79bd164
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
7 changes: 7 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ CHANGES
4.2.0 (Unreleased)
------------------

General:

* #149 Added a clear message on ImportError when the psycopg2
package cannot be found.
Please refer to the following site for more information:
https://django-redshift-backend.readthedocs.io/en/master/basic.html#installation

Features:

* #143 Add Django-5.0 support.
Expand Down
11 changes: 8 additions & 3 deletions django_redshift_backend/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,18 @@
import django
from django.utils import timezone
from django.conf import settings
from django.core.exceptions import FieldDoesNotExist
from django.core.exceptions import FieldDoesNotExist, ImproperlyConfigured
from django.db.models import Index
from django.db.models.expressions import Col
from django.db.utils import NotSupportedError, ProgrammingError

try:
from psycopg2.extensions import Binary
except ImportError:
raise ImproperlyConfigured(
"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"
)

from ._vendor.django40.db.backends.base.introspection import FieldInfo, TableInfo
from ._vendor.django40.db.backends.base.schema import (
_is_relevant_relation,
Expand All @@ -37,8 +44,6 @@
DatabaseIntrospection as BasePGDatabaseIntrospection,
)
from .meta import DistKey, SortKey
from psycopg2.extensions import Binary

from .psycopg2adapter import RedshiftBinary

logger = logging.getLogger("django.db.backends")
Expand Down
3 changes: 1 addition & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@ DJANGO =

[testenv]
deps =
.[psycopg2-binary]
coverage
psycopg2-binary>=2.7
pytest
pytest-cov
mock>=2.0
django-environ
py38: backports.zoneinfo
dj32: Django>=3.2,<3.3
dj40: Django>=4.0,<4.1
dj42: Django>=4.2,<5.0
Expand Down

0 comments on commit 79bd164

Please sign in to comment.