Skip to content

Commit

Permalink
Merge pull request #913 from Jigsaw52/psycopg3_support
Browse files Browse the repository at this point in the history
Add support for psycopg3
  • Loading branch information
tomturner committed Apr 18, 2023
2 parents 5f25990 + 9cc46d1 commit 4a93305
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions django_tenants/postgresql_backend/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,20 @@
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ImproperlyConfigured, ValidationError
import django.db.utils
import psycopg2

try:
from django.db.backends.postgresql.psycopg_any import is_psycopg3
except ImportError:
is_psycopg3 = False

if is_psycopg3:
import psycopg
else:
import psycopg2 as psycopg


DatabaseError = django.db.utils.DatabaseError
IntegrityError = psycopg2.IntegrityError
IntegrityError = psycopg.IntegrityError

ORIGINAL_BACKEND = getattr(settings, 'ORIGINAL_BACKEND', 'django.db.backends.postgresql')

Expand Down Expand Up @@ -160,7 +169,7 @@ def _cursor(self, name=None):
try:
formatted_search_paths = ['\'{}\''.format(s) for s in search_paths]
cursor_for_search_path.execute('SET search_path = {0}'.format(','.join(formatted_search_paths)))
except (django.db.utils.DatabaseError, psycopg2.InternalError):
except (django.db.utils.DatabaseError, psycopg.InternalError):
self.search_path_set_schemas = None
else:
self.search_path_set_schemas = search_paths
Expand Down

0 comments on commit 4a93305

Please sign in to comment.