Skip to content

Commit

Permalink
Fix quotation marks being included in search path
Browse files Browse the repository at this point in the history
Example where search path is quoted:
```
db=# SET search_path = 'country_BD';
SET
farm2go=# SHOW search_path;
 search_path
--------------
 "country_BD"
(1 row)
```
  • Loading branch information
libcthorne authored and atodorov committed May 3, 2023
1 parent 4ec3800 commit 7d066d7
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions django_tenants/postgresql_backend/introspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}')
Expand Down

0 comments on commit 7d066d7

Please sign in to comment.