: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
perf(hogql): fetch warehouse catalog narrowly in cache fingerprint (#69568)
Thomas Obermüller7ea5ca3449e8
diff --git a/posthog/hogql_queries/access_controlled_resources.py b/posthog/hogql_queries/access_controlled_resources.pyindex 82096cb01e19..06b7b29509de 100644--- a/posthog/hogql_queries/access_controlled_resources.py+++ b/posthog/hogql_queries/access_controlled_resources.py@@ -54,7 +54,17 @@ def queried_access_controlled_resources(query, team: "Team") -> Optional[set[strfor table in (DataWarehouseTable.objects.filter(team_id=team.pk).exclude(deleted=True)+ # clear the manager's created_by/schema eager-loads: select_related chains additively,+ # so without this the .only() below raises FieldError (created_by deferred + traversed)+ .select_related(None)+ .prefetch_related(None).select_related("external_data_source")+ .only(+ "name",+ "external_data_source__source_type",+ "external_data_source__prefix",+ "external_data_source__access_method",+ )):warehouse_table_names.add(table.name)warehouse_table_names.add(get_data_warehouse_table_name(table.external_data_source, table.name))diff --git a/posthog/hogql_queries/test/test_access_controlled_resources.py b/posthog/hogql_queries/test/test_access_controlled_resources.pyindex 4f910e80bb89..38ad4631d329 100644--- a/posthog/hogql_queries/test/test_access_controlled_resources.py+++ b/posthog/hogql_queries/test/test_access_controlled_resources.py@@ -134,6 +134,26 @@ class TestQueriedAccessControlledResources(BaseTest):)assert result == {"warehouse_table", "notebook"}+ def test_catalog_fetch_loads_only_name_fields(self):+ source = ExternalDataSource.objects.create(+ team=self.team,+ source_id="s",+ connection_id="c",+ status=ExternalDataSource.Status.COMPLETED,+ source_type=ExternalDataSourceType.STRIPE,+ prefix="myprefix",+ )+ table = self._create_warehouse_table("stripe_customers")+ table.external_data_source = source+ table.save()++ query = HogQLQuery(query="select * from stripe_customers")+ # One query each for tables and views. A third means either the .only() field list no+ # longer covers what get_data_warehouse_table_name reads (rows silently defer-load per+ # row) or the default manager's externaldataschema_set prefetch leaked back in.+ with self.assertNumQueries(2):+ assert queried_access_controlled_resources(query, self.team) == {"warehouse_table"}+def test_warehouse_table_of_another_team_not_matched(self):from posthog.models import Team