Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(health-checks): import JobOwners without booting the dagster package (#86772)

Daniel RC17f7dce8c8ca
diff --git a/.github/workflows/ci-dagster.yml b/.github/workflows/ci-dagster.yml
index 37ce25231e9b..0ef7d65685b1 100644
--- a/.github/workflows/ci-dagster.yml
+++ b/.github/workflows/ci-dagster.yml
@@ -129,6 +129,7 @@ jobs:
- 'posthog/exceptions_capture.py'
- 'posthog/metrics.py'
- 'posthog/git.py'
+ - 'posthog/job_owners.py'
- 'posthog/llm/**'
- 'posthog/person_db_router.py'
- 'posthog/persons_db.py'
diff --git a/posthog/dags/common/__init__.py b/posthog/dags/common/__init__.py
index ed112200e685..1a498d65df76 100644
--- a/posthog/dags/common/__init__.py
+++ b/posthog/dags/common/__init__.py
@@ -1,3 +1,5 @@
+from posthog.job_owners import JobOwners
+
from .common import (
check_for_concurrent_runs,
chunk_ranges,
@@ -5,7 +7,6 @@ from .common import (
settings_with_log_comment,
skip_if_already_running,
)
-from .owners import JobOwners
__all__ = [
"JobOwners",
diff --git a/posthog/dags/common/owners.py b/posthog/job_owners.py
similarity index 77%
rename from posthog/dags/common/owners.py
rename to posthog/job_owners.py
index 186a2c7774d7..1edd3eed9f58 100644
--- a/posthog/dags/common/owners.py
+++ b/posthog/job_owners.py
@@ -2,6 +2,12 @@ from enum import Enum
class JobOwners(str, Enum):
+ """Team that owns a scheduled job, used for alert routing.
+
+ Lives outside `posthog.dags` because Temporal and product code tag jobs with it too, and
+ importing anything under `posthog.dags` runs that package's Django bootstrap.
+ """
+
TEAM_ANALYTICS_PLATFORM = "team-analytics-platform"
TEAM_BILLING = "team-billing"
TEAM_CLICKHOUSE = "team-clickhouse"
@@ -9,7 +15,6 @@ class JobOwners(str, Enum):
TEAM_DATA_STACK = "team-data-stack"
TEAM_DATA_TOOLS = "team-data-tools"
TEAM_ERROR_TRACKING = "team-error-tracking"
-
TEAM_GROWTH = "team-growth"
TEAM_INGESTION = "team-ingestion"
TEAM_LOGS = "team-logs"
diff --git a/posthog/temporal/health_checks/framework.py b/posthog/temporal/health_checks/framework.py
index 36ebd233031b..471ae1f0f0bc 100644
--- a/posthog/temporal/health_checks/framework.py
+++ b/posthog/temporal/health_checks/framework.py
@@ -7,7 +7,7 @@ from typing import Any
from django.conf import settings
from posthog.clickhouse.query_tagging import Product
-from posthog.dags.common.owners import JobOwners
+from posthog.job_owners import JobOwners
from posthog.models.health_issue import HealthIssue
from posthog.temporal.health_checks.detectors import DEFAULT_EXECUTION_POLICY, HealthExecutionPolicy
from posthog.temporal.health_checks.models import DEFAULT_ACTIVE_SINCE_DAYS, HealthCheckResult
diff --git a/posthog/temporal/health_checks/tests/test_framework.py b/posthog/temporal/health_checks/tests/test_framework.py
index 502b72a16587..6f17d6644378 100644
--- a/posthog/temporal/health_checks/tests/test_framework.py
+++ b/posthog/temporal/health_checks/tests/test_framework.py
@@ -2,7 +2,7 @@ from typing import Any
import pytest
-from posthog.dags.common.owners import JobOwners
+from posthog.job_owners import JobOwners
from posthog.temporal.health_checks.framework import HealthCheckRegistration
diff --git a/posthog/test/repo_invariants/test_dagster_package_isolation.py b/posthog/test/repo_invariants/test_dagster_package_isolation.py
new file mode 100644
index 000000000000..4ebf5b232f40
--- /dev/null
+++ b/posthog/test/repo_invariants/test_dagster_package_isolation.py
@@ -0,0 +1,27 @@
+import sys
+import subprocess
+
+# A clean interpreter: pytest has already imported half the world, so this process cannot tell
+# which import pulled the package in.
+_SNAPSHOT = """
+import os
+os.environ.setdefault("DJANGO_SETTINGS_MODULE", "posthog.settings")
+import django
+django.setup()
+import posthog.temporal.health_checks.processing
+from posthog.temporal.health_checks.registry import ensure_registry_loaded
+ensure_registry_loaded()
+import sys
+print("posthog.dags" in sys.modules)
+"""
+
+
+def test_health_check_processing_does_not_import_the_dagster_package() -> None:
+ result = subprocess.run([sys.executable, "-c", _SNAPSHOT], capture_output=True, text=True, timeout=120)
+
+ assert result.returncode == 0, f"import failed:\n{result.stderr[-2000:]}"
+ assert result.stdout.strip() == "False", (
+ "Importing the Temporal health checks pulled in posthog.dags, whose __init__ runs "
+ "django.setup(). That re-applies LOGGING, and disable_existing_loggers turns off every "
+ "logger built before it. Import shared symbols such as JobOwners from posthog.job_owners."
+ )
diff --git a/products/cdp/backend/temporal/health_checks/ingestion_warnings.py b/products/cdp/backend/temporal/health_checks/ingestion_warnings.py
index 1b83afead789..6adbc0df807f 100644
--- a/products/cdp/backend/temporal/health_checks/ingestion_warnings.py
+++ b/products/cdp/backend/temporal/health_checks/ingestion_warnings.py
@@ -1,6 +1,6 @@
import structlog
-from posthog.dags.common.owners import JobOwners
+from posthog.job_owners import JobOwners
from posthog.models.health_issue import HealthIssue
from posthog.models.ingestion_warnings.sql_v2 import DISTRIBUTED_TABLE_NAME
from posthog.temporal.health_checks.detectors import CLICKHOUSE_BATCH_EXECUTION_POLICY
diff --git a/products/data_warehouse/backend/temporal/health_checks/external_data_failure.py b/products/data_warehouse/backend/temporal/health_checks/external_data_failure.py
index 04fd67999c63..2797228c4173 100644
--- a/products/data_warehouse/backend/temporal/health_checks/external_data_failure.py
+++ b/products/data_warehouse/backend/temporal/health_checks/external_data_failure.py
@@ -3,7 +3,7 @@ import datetime as dt
from django.db.models import Q
from django.utils import timezone
-from posthog.dags.common.owners import JobOwners
+from posthog.job_owners import JobOwners
from posthog.models.health_issue import HealthIssue
from posthog.temporal.health_checks.detectors import DEFAULT_EXECUTION_POLICY
from posthog.temporal.health_checks.framework import AlertContent, HealthCheck, Remediation
diff --git a/products/data_warehouse/backend/temporal/health_checks/materialized_view_failure.py b/products/data_warehouse/backend/temporal/health_checks/materialized_view_failure.py
index 7881f5d295d4..b01061916528 100644
--- a/products/data_warehouse/backend/temporal/health_checks/materialized_view_failure.py
+++ b/products/data_warehouse/backend/temporal/health_checks/materialized_view_failure.py
@@ -1,6 +1,6 @@
from django.db.models import Q
-from posthog.dags.common.owners import JobOwners
+from posthog.job_owners import JobOwners
from posthog.models.health_issue import HealthIssue
from posthog.temporal.health_checks.detectors import DEFAULT_EXECUTION_POLICY
from posthog.temporal.health_checks.framework import (
diff --git a/products/error_tracking/backend/temporal/health_checks/missing_source_maps.py b/products/error_tracking/backend/temporal/health_checks/missing_source_maps.py
index f4accf47511f..1f7a42482491 100644
--- a/products/error_tracking/backend/temporal/health_checks/missing_source_maps.py
+++ b/products/error_tracking/backend/temporal/health_checks/missing_source_maps.py
@@ -1,5 +1,5 @@
from posthog.clickhouse.query_tagging import Product
-from posthog.dags.common.owners import JobOwners
+from posthog.job_owners import JobOwners
from posthog.models.health_issue import HealthIssue
from posthog.temporal.health_checks.detectors import HealthExecutionPolicy
from posthog.temporal.health_checks.framework import AlertContent, HealthCheck, Remediation
diff --git a/products/growth/backend/temporal/health_checks/sdk_outdated.py b/products/growth/backend/temporal/health_checks/sdk_outdated.py
index 41eb8fc37060..783d2744c3e5 100644
--- a/products/growth/backend/temporal/health_checks/sdk_outdated.py
+++ b/products/growth/backend/temporal/health_checks/sdk_outdated.py
@@ -4,7 +4,7 @@ from typing import Any
import structlog
-from posthog.dags.common.owners import JobOwners
+from posthog.job_owners import JobOwners
from posthog.models.health_issue import HealthIssue
from posthog.redis import get_client
from posthog.temporal.health_checks.detectors import HealthExecutionPolicy
diff --git a/products/web_analytics/backend/max_tools.py b/products/web_analytics/backend/max_tools.py
index bb161b17cbe3..f2474363ab49 100644
--- a/products/web_analytics/backend/max_tools.py
+++ b/products/web_analytics/backend/max_tools.py
@@ -18,9 +18,9 @@ from posthog.hogql.parser import parse_expr, parse_select
from posthog.hogql.query import execute_hogql_query
from posthog.clickhouse.query_tagging import Product, tags_context
-from posthog.dags.common.owners import JobOwners
from posthog.hogql_queries.property_values_query_runner import PropertyValuesQueryRunner
from posthog.hogql_queries.query_runner import ExecutionMode
+from posthog.job_owners import JobOwners
from posthog.models import Team, User
from posthog.models.health_issue import HealthIssue
from posthog.queries.property_values import get_person_property_values_for_key
diff --git a/products/web_analytics/backend/temporal/health_checks/authorized_urls.py b/products/web_analytics/backend/temporal/health_checks/authorized_urls.py
index dbd2bc0c376f..3720728dea44 100644
--- a/products/web_analytics/backend/temporal/health_checks/authorized_urls.py
+++ b/products/web_analytics/backend/temporal/health_checks/authorized_urls.py
@@ -1,6 +1,6 @@
from django.db.models import Q
-from posthog.dags.common.owners import JobOwners
+from posthog.job_owners import JobOwners
from posthog.models.health_issue import HealthIssue
from posthog.models.team import Team
from posthog.temporal.health_checks.detectors import DEFAULT_EXECUTION_POLICY
diff --git a/products/web_analytics/backend/temporal/health_checks/no_live_events.py b/products/web_analytics/backend/temporal/health_checks/no_live_events.py
index 89b1eae6fb33..12954b362d5d 100644
--- a/products/web_analytics/backend/temporal/health_checks/no_live_events.py
+++ b/products/web_analytics/backend/temporal/health_checks/no_live_events.py
@@ -1,5 +1,5 @@
from posthog.clickhouse.query_tagging import Product
-from posthog.dags.common.owners import JobOwners
+from posthog.job_owners import JobOwners
from posthog.models.health_issue import HealthIssue
from posthog.temporal.health_checks.detectors import CLICKHOUSE_BATCH_EXECUTION_POLICY
from posthog.temporal.health_checks.framework import (
diff --git a/products/web_analytics/backend/temporal/health_checks/no_pageleave_events.py b/products/web_analytics/backend/temporal/health_checks/no_pageleave_events.py
index 6f6a06bb696d..e327620a4c02 100644
--- a/products/web_analytics/backend/temporal/health_checks/no_pageleave_events.py
+++ b/products/web_analytics/backend/temporal/health_checks/no_pageleave_events.py
@@ -1,5 +1,5 @@
from posthog.clickhouse.query_tagging import Product
-from posthog.dags.common.owners import JobOwners
+from posthog.job_owners import JobOwners
from posthog.models.health_issue import HealthIssue
from posthog.temporal.health_checks.detectors import CLICKHOUSE_BATCH_EXECUTION_POLICY
from posthog.temporal.health_checks.framework import (
diff --git a/products/web_analytics/backend/temporal/health_checks/partial_proxy.py b/products/web_analytics/backend/temporal/health_checks/partial_proxy.py
index 7b6ac41b406d..63e7af2f2fc4 100644
--- a/products/web_analytics/backend/temporal/health_checks/partial_proxy.py
+++ b/products/web_analytics/backend/temporal/health_checks/partial_proxy.py
@@ -1,7 +1,7 @@
import re
from collections import defaultdict
-from posthog.dags.common.owners import JobOwners
+from posthog.job_owners import JobOwners
from posthog.models.health_issue import HealthIssue
from posthog.temporal.health_checks.detectors import CLICKHOUSE_BATCH_EXECUTION_POLICY
from posthog.temporal.health_checks.framework import (
diff --git a/products/web_analytics/backend/temporal/health_checks/path_cleaning_suggestions.py b/products/web_analytics/backend/temporal/health_checks/path_cleaning_suggestions.py
index 7e1fb490150d..b464a3e58100 100644
--- a/products/web_analytics/backend/temporal/health_checks/path_cleaning_suggestions.py
+++ b/products/web_analytics/backend/temporal/health_checks/path_cleaning_suggestions.py
@@ -3,7 +3,7 @@ from django.conf import settings
import structlog
from posthog.clickhouse.query_tagging import Product
-from posthog.dags.common.owners import JobOwners
+from posthog.job_owners import JobOwners
from posthog.models import Team
from posthog.models.health_issue import HealthIssue
from posthog.temporal.health_checks.detectors import HealthExecutionPolicy
diff --git a/products/web_analytics/backend/temporal/health_checks/reverse_proxy.py b/products/web_analytics/backend/temporal/health_checks/reverse_proxy.py
index fdd5ee559c68..996e5ba77e41 100644
--- a/products/web_analytics/backend/temporal/health_checks/reverse_proxy.py
+++ b/products/web_analytics/backend/temporal/health_checks/reverse_proxy.py
@@ -1,4 +1,4 @@
-from posthog.dags.common.owners import JobOwners
+from posthog.job_owners import JobOwners
from posthog.models.health_issue import HealthIssue
from posthog.temporal.health_checks.detectors import CLICKHOUSE_BATCH_EXECUTION_POLICY
from posthog.temporal.health_checks.framework import (
diff --git a/products/web_analytics/backend/temporal/health_checks/scroll_depth.py b/products/web_analytics/backend/temporal/health_checks/scroll_depth.py
index 20af5fa84662..b7dd641f6332 100644
--- a/products/web_analytics/backend/temporal/health_checks/scroll_depth.py
+++ b/products/web_analytics/backend/temporal/health_checks/scroll_depth.py
@@ -1,4 +1,4 @@
-from posthog.dags.common.owners import JobOwners
+from posthog.job_owners import JobOwners
from posthog.models.health_issue import HealthIssue
from posthog.temporal.health_checks.detectors import CLICKHOUSE_BATCH_EXECUTION_POLICY
from posthog.temporal.health_checks.framework import (
diff --git a/products/web_analytics/backend/temporal/health_checks/web_vitals.py b/products/web_analytics/backend/temporal/health_checks/web_vitals.py
index ecd2b4675d7c..03f034219a05 100644
--- a/products/web_analytics/backend/temporal/health_checks/web_vitals.py
+++ b/products/web_analytics/backend/temporal/health_checks/web_vitals.py
@@ -1,4 +1,4 @@
-from posthog.dags.common.owners import JobOwners
+from posthog.job_owners import JobOwners
from posthog.models.health_issue import HealthIssue
from posthog.temporal.health_checks.detectors import CLICKHOUSE_BATCH_EXECUTION_POLICY
from posthog.temporal.health_checks.framework import (