fix migrations for template schema

Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space>
This commit is contained in:
Marc 'risson' Schmitt 2023-11-21 18:34:52 +01:00
parent 742dc12656
commit a5cc3c36ed
No known key found for this signature in database
GPG Key ID: 9C3FA22FABF1AA8D
2 changed files with 5 additions and 3 deletions

View File

@ -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):

View File

@ -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()