Content type cache should be cleared not just at the beginning of a request, but *anytime* the schema is changed (which happens in middle of requests). set_tenant() will also now result in a set_schema() call so it will claer_cache() at the beginning of a request, and on subsequent set_schema calls
This commit is contained in:
parent
86c4050856
commit
7e104037c9
|
@ -62,15 +62,6 @@ class BaseTenantMiddleware(MIDDLEWARE_MIXIN):
|
|||
request.tenant = tenant
|
||||
connection.set_tenant(request.tenant)
|
||||
|
||||
# Content type can no longer be cached as public and tenant schemas
|
||||
# have different models. If someone wants to change this, the cache
|
||||
# needs to be separated between public and shared schemas. If this
|
||||
# cache isn't cleared, this can cause permission problems. For example,
|
||||
# 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()
|
||||
|
||||
# Do we have a public-specific urlconf?
|
||||
if hasattr(settings, 'PUBLIC_SCHEMA_URLCONF') and request.tenant.schema_name == get_public_schema_name():
|
||||
request.urlconf = settings.PUBLIC_SCHEMA_URLCONF
|
||||
|
|
|
@ -3,6 +3,7 @@ import warnings
|
|||
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
|
||||
|
||||
|
@ -80,6 +81,14 @@ class DatabaseWrapper(original_backend.DatabaseWrapper):
|
|||
self.include_public_schema = include_public
|
||||
self.set_settings_schema(schema_name)
|
||||
self.search_path_set = False
|
||||
# Content type can no longer be cached as public and tenant schemas
|
||||
# have different models. If someone wants to change this, the cache
|
||||
# needs to be separated between public and shared schemas. If this
|
||||
# cache isn't cleared, this can cause permission problems. For example,
|
||||
# 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()
|
||||
|
||||
def set_schema_to_public(self):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue