diff --git a/django_tenants/postgresql_backend/introspection.py b/django_tenants/postgresql_backend/introspection.py index 281ff252..1a2f2ec0 100644 --- a/django_tenants/postgresql_backend/introspection.py +++ b/django_tenants/postgresql_backend/introspection.py @@ -13,12 +13,15 @@ def __init__(self, cursor, connection): def __enter__(self): self.cursor.execute('SHOW search_path') - self.original_search_path = self.cursor.fetchone()[0].split(',') + self.original_search_path = [ + search_path.strip().replace('"', '') + for search_path in self.cursor.fetchone()[0].split(',') + ] self.cursor.execute(f"SET search_path = '{self.connection.schema_name}'") def __exit__(self, *args, **kwargs): formatted_search_paths = ', '.join( - f"'{search_path.strip()}'" + f"'{search_path}'" for search_path in self.original_search_path ) self.cursor.execute(f'SET search_path = {formatted_search_paths}')