Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

delaying import of ContentType until django is fully loaded #688

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions tenant_schemas/postgresql_backend/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import psycopg2

from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ImproperlyConfigured, ValidationError
import django.db.utils

Expand Down Expand Up @@ -76,6 +75,7 @@ def set_schema(self, schema_name, include_public=True):
Main API method to current database schema,
but it does not actually modify the db connection.
"""
is_init = not hasattr(self, 'schema_name')
self.tenant = FakeTenant(schema_name=schema_name)
self.schema_name = schema_name
self.include_public_schema = include_public
Expand All @@ -88,7 +88,9 @@ def set_schema(self, schema_name, include_public=True):
# on public, a particular model has id 14, but on the tenants it has
# the id 15. if 14 is cached instead of 15, the permissions for the
# wrong model will be fetched.
ContentType.objects.clear_cache()
if not is_init:
from django.contrib.contenttypes.models import ContentType
ContentType.objects.clear_cache()

def set_schema_to_public(self):
"""
Expand Down