Revert "try with connection_created signal"

This reverts commit 764a999db8.
This commit is contained in:
Marc 'risson' Schmitt 2024-01-09 16:39:27 +01:00
parent 9c7600e1f2
commit 250e212703
No known key found for this signature in database
GPG Key ID: 9C3FA22FABF1AA8D
1 changed files with 3 additions and 14 deletions

View File

@ -1,25 +1,14 @@
"""authentik tenants app"""
from django.core.signals import setting_changed
from django.db import DEFAULT_DB_ALIAS
from django.db.backends.signals import connection_created
from django.db.models.signals import post_migrate
from django_tenants.utils import get_public_schema_name
from authentik.blueprints.apps import ManagedAppConfig
def ensure_default_tenant(*args, using=DEFAULT_DB_ALIAS, connection=None, **kwargs):
def ensure_default_tenant(*args, using=DEFAULT_DB_ALIAS, **kwargs):
"""Make sure default tenant exists"""
# Make sure we've migrated before touching the database
if connection is not None:
with connection.cursor() as cursor:
cursor.execute(
"SELECT * FROM information_schema.tables "
"WHERE table_schema = 'public' AND table_name = 'authentik_tenants_tenant'"
)
if not bool(cursor.rowcount):
return
using = connection.alias
from django_tenants.utils import schema_context
from authentik.tenants.models import Tenant
@ -43,4 +32,4 @@ class AuthentikTenantsConfig(ManagedAppConfig):
"""Make sure default tenant exists, especially after a migration"""
ensure_default_tenant()
post_migrate.connect(ensure_default_tenant)
connection_created.connect(ensure_default_tenant)
setting_changed.connect(ensure_default_tenant)