diff --git a/authentik/events/monitored_tasks.py b/authentik/events/monitored_tasks.py index efb598be3..4dbd0678c 100644 --- a/authentik/events/monitored_tasks.py +++ b/authentik/events/monitored_tasks.py @@ -6,6 +6,7 @@ from timeit import default_timer from typing import Any, Optional from django.core.cache import cache +from django.db.utils import ProgrammingError from django.utils.translation import gettext_lazy as _ from structlog.stdlib import get_logger from tenant_schemas_celery.task import TenantTask @@ -101,8 +102,13 @@ class TaskInfo: duration = max(self.finish_timestamp - start, 0) except TypeError: duration = 0 + try: + tenant = get_current_tenant().tenant_uuid + # DB not yet initialized, let's not fail + except ProgrammingError: + tenant = "" GAUGE_TASKS.labels( - tenant=get_current_tenant().tenant_uuid, + tenant=tenant, task_name=self.task_name.split(":")[0], task_uid=self.result.uid or "", status=self.result.status.name.lower(),