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

fix: do not fail in initial migrations if PG_EXTRA_SEARCH_PATHS … #622

Open
wants to merge 1 commit 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
16 changes: 10 additions & 6 deletions tenant_schemas/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.conf import settings
from django.core.checks import Critical, Error, Warning, register
from django.core.files.storage import default_storage
from django.db import connection
from tenant_schemas.storage import TenantStorageMixin
from tenant_schemas.utils import get_public_schema_name, get_tenant_model

Expand Down Expand Up @@ -67,12 +68,15 @@ def best_practice(app_configs, **kwargs):
% get_public_schema_name()))

# make sure no tenant schema is in settings.PG_EXTRA_SEARCH_PATHS
invalid_schemas = set(settings.PG_EXTRA_SEARCH_PATHS).intersection(
get_tenant_model().objects.all().values_list('schema_name', flat=True))
if invalid_schemas:
errors.append(Critical(
"Do not include tenant schemas (%s) on PG_EXTRA_SEARCH_PATHS."
% ", ".join(sorted(invalid_schemas))))
tenant_model = get_tenant_model()
# but avoid check during initial migration(s) when the table for tenant model is not created yet
if tenant_model._meta.db_table in connection.introspection.table_names():
invalid_schemas = set(settings.PG_EXTRA_SEARCH_PATHS).intersection(
tenant_model.objects.all().values_list('schema_name', flat=True))
if invalid_schemas:
errors.append(Critical(
"Do not include tenant schemas (%s) on PG_EXTRA_SEARCH_PATHS."
% ", ".join(sorted(invalid_schemas))))

if not settings.SHARED_APPS:
errors.append(
Expand Down