Skip to content

Commit

Permalink
Inherit tenant_context() from schema_context()
Browse files Browse the repository at this point in the history
less possibilities for code to diverge over time
  • Loading branch information
atodorov committed Dec 8, 2019
1 parent 44b0bf7 commit 83de44a
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions django_tenants/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,9 @@ def __exit__(self, *exc):
self.connection.set_tenant(self.previous_tenant)


class tenant_context(ContextDecorator):
class tenant_context(schema_context):
def __init__(self, *args, **kwargs):
self.tenant = args[0]
super().__init__()

def __enter__(self):
self.connection = connections[get_tenant_database_alias()]
self.previous_tenant = connection.tenant
self.connection.set_tenant(self.tenant)

def __exit__(self, *exc):
if self.previous_tenant is None:
self.connection.set_schema_to_public()
else:
self.connection.set_tenant(self.previous_tenant)
super().__init__(args[0].schema_name, **kwargs)


def clean_tenant_url(url_string):
Expand Down

0 comments on commit 83de44a

Please sign in to comment.