From c48e8e8d75760afa2f041e346eed04772d8c55e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mirek=20Zvolsk=C3=BD?= Date: Mon, 17 Feb 2020 11:46:00 +0100 Subject: [PATCH] fix: do not fail in initial migrations if PG_EXTRA_SEARCH_PATHS is defined --- tenant_schemas/apps.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tenant_schemas/apps.py b/tenant_schemas/apps.py index 6b16b621..cf4b7bc6 100644 --- a/tenant_schemas/apps.py +++ b/tenant_schemas/apps.py @@ -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 @@ -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(