Skip to content

Commit

Permalink
Fix for psql support
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienrusso committed Nov 22, 2021
1 parent 1d430b2 commit c6f19b8
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions django_tenants/postgresql_backend/introspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ def __init__(self, cursor, connection):

def __enter__(self):
self.cursor.execute('SHOW search_path')
self.original_search_path = self.cursor.fetchone()[0]
self.cursor.execute("SET search_path = %s" % self.connection.schema_name)
self.original_search_path = self.cursor.fetchone()[0].split(',')
self.cursor.execute(f"SET search_path = '{self.connection.schema_name}'")

def __exit__(self, *args, **kwargs):
self.cursor.execute("SET search_path = %s" % self.original_search_path)
formatted_search_paths = ', '.join(
f"'{search_path.strip()}'"
for search_path in self.original_search_path
)
self.cursor.execute(f'SET search_path = {formatted_search_paths}')


class DatabaseSchemaIntrospection(DatabaseIntrospection):
Expand Down

0 comments on commit c6f19b8

Please sign in to comment.