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.

chore(temporal): clarify migration discovery setup comment (#65946)

Phil Haackd863e49f76c1
diff --git a/posthog/schema_migrations/__init__.py b/posthog/schema_migrations/__init__.py
index 9b783b546edb..bb5b0f377f91 100644
--- a/posthog/schema_migrations/__init__.py
+++ b/posthog/schema_migrations/__init__.py
@@ -10,7 +10,7 @@ logger = structlog.get_logger(__name__)
LATEST_VERSIONS: dict[str, int] = {}
MIGRATIONS: dict[str, dict[int, SchemaMigration]] = {}
-_migrations_discovered = False
+_migrations_discovered: bool = False
def _discover_migrations():
diff --git a/posthog/temporal/tests/product_analytics/test_upgrade_queries_workflow.py b/posthog/temporal/tests/product_analytics/test_upgrade_queries_workflow.py
index 1d59a4b2c0a9..5d02fcadf660 100644
--- a/posthog/temporal/tests/product_analytics/test_upgrade_queries_workflow.py
+++ b/posthog/temporal/tests/product_analytics/test_upgrade_queries_workflow.py
@@ -80,6 +80,14 @@ def setup_migrations():
LATEST_VERSIONS[NodeKind.TRENDS_QUERY] = 6
LATEST_VERSIONS[NodeKind.EVENTS_NODE] = 8
+ # Mark discovery as already done so only the mock registry above is used.
+ # Without this, anything that calls upgrade() mid-test (for example, saving
+ # an Insight) would trigger _discover_migrations(), which lazily loads the
+ # real on-disk migrations and merges them into these globals. That would
+ # make the generated query (and its snapshot) depend on whether an earlier
+ # test already ran discovery.
+ schema_migrations_module._migrations_discovered = True
+
yield
LATEST_VERSIONS.clear()