: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(hogql): scope taxonomy validation lookups by project (#92286)
José Sequeira0c8a201b0240
diff --git a/posthog/hogql/taxonomy_validation.py b/posthog/hogql/taxonomy_validation.pyindex 61460bab16e0..3c8fae2422aa 100644--- a/posthog/hogql/taxonomy_validation.py+++ b/posthog/hogql/taxonomy_validation.py@@ -14,6 +14,8 @@ from posthog.hogql.visitor import TraversingVisitorfrom posthog.models import EventDefinition, PropertyDefinition, Team+from products.event_definitions.backend.models.property_definition import effective_project_id_expr+logger = getLogger(__name__)# How a suggested name is rendered back into the marked range for a one-click fix:@@ -110,7 +112,11 @@ def validate_taxonomy_references(if visitor.event_literals:warnings.extend(_warnings_for_unknown_references(- "Event", visitor.event_literals, EventDefinition.objects.filter(team=team)+ "Event",+ visitor.event_literals,+ EventDefinition.objects.alias(effective_project_id=effective_project_id_expr()).filter(+ effective_project_id=team.project_id+ ),))@@ -123,7 +129,9 @@ def validate_taxonomy_references(_warnings_for_unknown_references("Property",property_references,- PropertyDefinition.objects.filter(team=team, type=PropertyDefinition.Type.EVENT),+ PropertyDefinition.objects.alias(effective_project_id=effective_project_id_expr()).filter(+ effective_project_id=team.project_id, type=PropertyDefinition.Type.EVENT+ ),))except DatabaseError:diff --git a/posthog/hogql/test/test_metadata.py b/posthog/hogql/test/test_metadata.pyindex fde5cb52177e..5f3fe0d294b9 100644--- a/posthog/hogql/test/test_metadata.py+++ b/posthog/hogql/test/test_metadata.py@@ -366,7 +366,7 @@ class TestMetadata(ClickhouseTestMixin, APIBaseTest):EventDefinition.objects.create(team=self.team, name="paid_bill")with patch(- "posthog.hogql.taxonomy_validation.EventDefinition.objects.filter",+ "posthog.hogql.taxonomy_validation.EventDefinition.objects.alias",side_effect=DatabaseError("boom"),):metadata = self._select("SELECT count() FROM events WHERE event = 'purchase'")@@ -377,14 +377,14 @@ class TestMetadata(ClickhouseTestMixin, APIBaseTest):def test_metadata_does_not_query_taxonomy_without_taxonomy_references(self):with (- patch("posthog.hogql.taxonomy_validation.EventDefinition.objects.filter") as event_filter,- patch("posthog.hogql.taxonomy_validation.PropertyDefinition.objects.filter") as property_filter,+ patch("posthog.hogql.taxonomy_validation.EventDefinition.objects.alias") as event_alias,+ patch("posthog.hogql.taxonomy_validation.PropertyDefinition.objects.alias") as property_alias,):metadata = self._select("SELECT count() FROM events")self.assertTrue(metadata.isValid)- event_filter.assert_not_called()- property_filter.assert_not_called()+ event_alias.assert_not_called()+ property_alias.assert_not_called()def test_metadata_does_not_warn_for_event_column_outside_events_table(self):EventDefinition.objects.create(team=self.team, name="paid_bill")