From 7d066d7557f97e2aa10dcc5e1e485b150a3ddb4d Mon Sep 17 00:00:00 2001 From: Christopher Thorne Date: Mon, 12 Sep 2022 15:50:06 +0100 Subject: [PATCH] Fix quotation marks being included in search path Example where search path is quoted: ``` db=# SET search_path = 'country_BD'; SET farm2go=# SHOW search_path; search_path -------------- "country_BD" (1 row) ``` --- django_tenants/postgresql_backend/introspection.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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}')