From c6f19b84b2c91754652a250bd3097a88daaed4ef Mon Sep 17 00:00:00 2001 From: Adrien Russo Date: Mon, 22 Nov 2021 18:05:33 -0500 Subject: [PATCH] Fix for psql support --- django_tenants/postgresql_backend/introspection.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/django_tenants/postgresql_backend/introspection.py b/django_tenants/postgresql_backend/introspection.py index 554a7e9f..281ff252 100644 --- a/django_tenants/postgresql_backend/introspection.py +++ b/django_tenants/postgresql_backend/introspection.py @@ -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):