From a5cc3c36ed5cfcda081d11fca7f116b10c226f59 Mon Sep 17 00:00:00 2001 From: Marc 'risson' Schmitt Date: Tue, 21 Nov 2023 18:34:52 +0100 Subject: [PATCH] fix migrations for template schema Signed-off-by: Marc 'risson' Schmitt --- authentik/policies/reputation/models.py | 4 +++- authentik/tenants/utils.py | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/authentik/policies/reputation/models.py b/authentik/policies/reputation/models.py index e2b216b44..d3cf58bb3 100644 --- a/authentik/policies/reputation/models.py +++ b/authentik/policies/reputation/models.py @@ -15,6 +15,7 @@ from authentik.lib.models import SerializerModel from authentik.lib.utils.http import get_client_ip from authentik.policies.models import Policy from authentik.policies.types import PolicyRequest, PolicyResult +from authentik.tenants.models import Tenant from authentik.tenants.utils import get_current_tenant LOGGER = get_logger() @@ -23,7 +24,8 @@ CACHE_KEY_PREFIX = "goauthentik.io/policies/reputation/scores/" def reputation_expiry(): """Reputation expiry""" - return now() + timedelta(seconds=get_current_tenant().reputation_expiry) + tenant = get_current_tenant() or Tenant() # Needed if we are running in a migration + return now() + timedelta(seconds=tenant.reputation_expiry) class ReputationPolicy(Policy): diff --git a/authentik/tenants/utils.py b/authentik/tenants/utils.py index aabc2e931..bb000ed3c 100644 --- a/authentik/tenants/utils.py +++ b/authentik/tenants/utils.py @@ -4,6 +4,6 @@ from django.db import connection from authentik.tenants.models import Tenant -def get_current_tenant() -> Tenant: +def get_current_tenant() -> Tenant | None: """Get tenant for current request""" - return Tenant.objects.get(schema_name=connection.schema_name) + return Tenant.objects.filter(schema_name=connection.schema_name).first()