: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: infer saved-query and endpoint columns as the acting user (#72599)
Alex Lider03812bd32f1d
diff --git a/products/data_modeling/backend/models/datawarehouse_saved_query.py b/products/data_modeling/backend/models/datawarehouse_saved_query.pyindex e7ea57f860c9..7782ab3f66d5 100644--- a/products/data_modeling/backend/models/datawarehouse_saved_query.py+++ b/products/data_modeling/backend/models/datawarehouse_saved_query.py@@ -13,6 +13,8 @@ import structlogif TYPE_CHECKING:from posthog.schema import HogQLQueryModifiers+ from posthog.models.user import User+from posthog.hogql import astfrom posthog.hogql.database.database import Databasefrom posthog.hogql.database.direct_mysql_table import DirectMySQLTable@@ -269,7 +271,7 @@ class DataWarehouseSavedQuery(CreatedMetaFields, UUIDTModel, UpdatedMetaFields,self.columns = columnsself.column_order = list(columns.keys())- def get_columns(self) -> dict[str, dict[str, Any]]:+ def get_columns(self, user: Optional["User"] = None) -> dict[str, dict[str, Any]]:from posthog.api.services.query import process_query_dictfrom posthog.clickhouse.query_tagging import Feature, Product, tags_contextfrom posthog.hogql_queries.query_runner import ExecutionMode@@ -283,8 +285,12 @@ class DataWarehouseSavedQuery(CreatedMetaFields, UUIDTModel, UpdatedMetaFields,if "kind" not in query and "query" in query:query = {"kind": "HogQLQuery", **query}+ # Resolve as the acting user so warehouse access control is enforced against them - a userless+ # build fails closed and denies every warehouse table, breaking column inference for all users.with tags_context(product=Product.WAREHOUSE, feature=Feature.DATA_MODELING):- response = process_query_dict(self.team, query, execution_mode=ExecutionMode.CALCULATE_BLOCKING_ALWAYS)+ response = process_query_dict(+ self.team, query, execution_mode=ExecutionMode.CALCULATE_BLOCKING_ALWAYS, user=user+ )result = getattr(response, "types", [])if result is None or isinstance(result, int):diff --git a/products/data_warehouse/backend/presentation/views/saved_query.py b/products/data_warehouse/backend/presentation/views/saved_query.pyindex c840cb324181..b862bf1a50ff 100644--- a/products/data_warehouse/backend/presentation/views/saved_query.py+++ b/products/data_warehouse/backend/presentation/views/saved_query.py@@ -440,7 +440,7 @@ class DataWarehouseSavedQuerySerializer(# The columns will be inferred from the queryclient_types = self.context["request"].data.get("types", [])if len(client_types) == 0:- view.set_columns(view.get_columns())+ view.set_columns(view.get_columns(user=self.context["request"].user))else:columns = {str(item[0]): {@@ -581,7 +581,7 @@ class DataWarehouseSavedQuerySerializer(# The columns will be inferred from the queryclient_types = self.context["request"].data.get("types", [])if len(client_types) == 0:- view.set_columns(view.get_columns())+ view.set_columns(view.get_columns(user=self.context["request"].user))else:columns = {str(item[0]): {diff --git a/products/endpoints/backend/models.py b/products/endpoints/backend/models.pyindex 526d011df7f0..3eb1c8668dcb 100644--- a/products/endpoints/backend/models.py+++ b/products/endpoints/backend/models.py@@ -330,7 +330,11 @@ class EndpointVersion(UpdatedMetaFields, models.Model):cleaned = _PLACEHOLDER_REPLACER.visit(parsed)team = Team.objects.get(pk=team_id)- executor = HogQLQueryExecutor(query=cleaned, team=team, limit_context=None)+ # Bypass warehouse access control: DESCRIBE exposes only column names/types, never rows, and+ # `columns` is a shared cache that must be the same for every reader.+ executor = HogQLQueryExecutor(+ query=cleaned, team=team, limit_context=None, bypass_warehouse_access_control=True+ )clickhouse_sql, clickhouse_context = executor.generate_clickhouse_sql()if not clickhouse_sql: