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(data-modeling): infer saved query columns with LIMIT 0 (#112874)

Sandy Spicer420e74cb52b2
diff --git a/docs/published/handbook/engineering/data-warehouse.md b/docs/published/handbook/engineering/data-warehouse.md
index 0b67fdbd6740..8c1bbeee4f9d 100644
--- a/docs/published/handbook/engineering/data-warehouse.md
+++ b/docs/published/handbook/engineering/data-warehouse.md
@@ -18,6 +18,10 @@ This reservation does not add qualified names to existing models or require a na
## SQL editor drafts
+Saving a view infers its column types with LIMIT 0 on the outer SELECT branches and explicit IN subqueries.
+Scalar subqueries can still read data, so column inference shares the organization's foreground query concurrency limit.
+API-key requests and background jobs retain the query runner's existing exemptions from that limit.
+
The SQL editor keeps unrun edits in browser storage, scoped to the user, project, and saved query. Explicit logout clears these drafts.
An **Edited** label marks changes to a saved view or insight. **Discard changes** restores the saved copy already loaded in memory, then refreshes it from the server. The refresh preserves edits made after discarding.
Insights can be saved or updated before running the SQL. Updating a view still requires a successful run of the current SQL so its result types match the saved query. **Continue in a notebook** is in the update button's dropdown for saved views and insights.
diff --git a/posthog/api/test/__snapshots__/test_query.ambr b/posthog/api/test/__snapshots__/test_query.ambr
index 573c54f3eb35..d62f94384fbc 100644
--- a/posthog/api/test/__snapshots__/test_query.ambr
+++ b/posthog/api/test/__snapshots__/test_query.ambr
@@ -206,19 +206,18 @@
FROM events
WHERE equals(events.team_id, 99999)
ORDER BY toTimeZone(events.timestamp, 'UTC') ASC
- LIMIT 101
- OFFSET 0 SETTINGS readonly=2,
- max_execution_time=60,
- allow_experimental_object_type=1,
- max_ast_elements=4000000,
- max_expanded_ast_elements=4000000,
- max_bytes_before_external_group_by=0,
- transform_null_in=1,
- optimize_min_equality_disjunction_chain_length=4294967295,
- optimize_rewrite_aggregate_function_with_if=0,
- optimize_min_inequality_conjunction_chain_length=4294967295,
- allow_experimental_join_condition=1,
- use_hive_partitioning=0
+ LIMIT 0 SETTINGS readonly=2,
+ max_execution_time=60,
+ allow_experimental_object_type=1,
+ max_ast_elements=4000000,
+ max_expanded_ast_elements=4000000,
+ max_bytes_before_external_group_by=0,
+ transform_null_in=1,
+ optimize_min_equality_disjunction_chain_length=4294967295,
+ optimize_rewrite_aggregate_function_with_if=0,
+ optimize_min_inequality_conjunction_chain_length=4294967295,
+ allow_experimental_join_condition=1,
+ use_hive_partitioning=0
'''
# ---
# name: TestQuery.test_full_hogql_query_view.1
diff --git a/posthog/api/test/__snapshots__/test_query.new_events_schema.ambr b/posthog/api/test/__snapshots__/test_query.new_events_schema.ambr
index f4ebf67eebc2..268cc4c03c83 100644
--- a/posthog/api/test/__snapshots__/test_query.new_events_schema.ambr
+++ b/posthog/api/test/__snapshots__/test_query.new_events_schema.ambr
@@ -242,20 +242,19 @@
FROM events_json AS events
WHERE equals(events.team_id, 99999)
ORDER BY toTimeZone(events.timestamp, 'UTC') ASC
- LIMIT 101
- OFFSET 0 SETTINGS readonly=2,
- max_execution_time=60,
- allow_experimental_object_type=1,
- max_ast_elements=4000000,
- max_expanded_ast_elements=4000000,
- max_bytes_before_external_group_by=0,
- transform_null_in=1,
- optimize_min_equality_disjunction_chain_length=4294967295,
- optimize_rewrite_aggregate_function_with_if=0,
- optimize_min_inequality_conjunction_chain_length=4294967295,
- allow_experimental_join_condition=1,
- use_hive_partitioning=0,
- json_type_escape_dots_in_keys=1
+ LIMIT 0 SETTINGS readonly=2,
+ max_execution_time=60,
+ allow_experimental_object_type=1,
+ max_ast_elements=4000000,
+ max_expanded_ast_elements=4000000,
+ max_bytes_before_external_group_by=0,
+ transform_null_in=1,
+ optimize_min_equality_disjunction_chain_length=4294967295,
+ optimize_rewrite_aggregate_function_with_if=0,
+ optimize_min_inequality_conjunction_chain_length=4294967295,
+ allow_experimental_join_condition=1,
+ use_hive_partitioning=0,
+ json_type_escape_dots_in_keys=1
'''
# ---
# name: TestQuery.test_hogql_property_filter[new_events_schema.1]
diff --git a/posthog/clickhouse/client/limit.py b/posthog/clickhouse/client/limit.py
index e2c88be7362d..b48fdb4ed725 100644
--- a/posthog/clickhouse/client/limit.py
+++ b/posthog/clickhouse/client/limit.py
@@ -1,24 +1,34 @@
import time
import uuid
import dataclasses
-from collections.abc import Callable
+from collections.abc import Callable, Iterator
from contextlib import contextmanager
from functools import wraps
from time import sleep
-from typing import Optional
+from typing import TYPE_CHECKING, Optional
from celery import current_task
from prometheus_client import Counter
from posthog import redis, settings
from posthog.clickhouse.backoff import ExponentialBackoff
-from posthog.clickhouse.query_tagging import Product, add_fallback_query_tags, get_query_tags, tag_queries
+from posthog.clickhouse.query_tagging import (
+ Product,
+ add_fallback_query_tags,
+ get_query_tag_value,
+ get_query_tags,
+ is_api_key_access_method,
+ tag_queries,
+)
from posthog.constants import AvailableFeature
from posthog.dataclasses import frozen
from posthog.schema_enums import ProductKey
from posthog.settings import TEST
from posthog.utils import generate_short_id
+if TYPE_CHECKING:
+ from posthog.models.team import Team
+
# Default concurrency limits
DEFAULT_APP_ORG_CONCURRENT_QUERIES = 20
DEFAULT_APP_DASHBOARD_CONCURRENT_QUERIES = 6
@@ -489,3 +499,15 @@ def get_org_app_concurrency_limit(org_id: uuid.UUID) -> Optional[int]:
pass
return None
+
+
+@contextmanager
+def app_org_concurrency_slot(team: "Team", *, task_id: str | None = None) -> Iterator[None]:
+ with get_app_org_rate_limiter().run(
+ org_id=team.organization_id,
+ team_id=team.pk,
+ task_id=task_id,
+ is_api=is_api_key_access_method(get_query_tag_value("access_method")),
+ limit=get_org_app_concurrency_limit(team.organization_id),
+ ):
+ yield
diff --git a/posthog/hogql_queries/query_runner.py b/posthog/hogql_queries/query_runner.py
index d6f8f3d5f4ff..e512382b14a5 100644
--- a/posthog/hogql_queries/query_runner.py
+++ b/posthog/hogql_queries/query_runner.py
@@ -151,11 +151,10 @@ from posthog.caching.utils import ThresholdMode, cache_target_age, is_stale, las
from posthog.clickhouse.client.connection import ClickHouseUser, Workload
from posthog.clickhouse.client.execute_async import QueryNotFoundError, enqueue_process_query_task, get_query_status
from posthog.clickhouse.client.limit import (
+ app_org_concurrency_slot,
get_api_team_rate_limiter,
get_app_dashboard_queries_rate_limiter,
- get_app_org_rate_limiter,
get_materialized_endpoints_rate_limiter,
- get_org_app_concurrency_limit,
)
from posthog.clickhouse.query_tagging import get_query_tag_value, is_api_key_access_method, tag_queries
from posthog.constants import AvailableFeature
@@ -2294,15 +2293,7 @@ class QueryRunner(ABC, Generic[Q, R, CR]):
limit=concurrency_limit,
)
)
- limiter_stack.enter_context(
- get_app_org_rate_limiter().run(
- org_id=self.team.organization_id,
- task_id=self.query_id,
- team_id=self.team.id,
- is_api=is_api_key_access,
- limit=get_org_app_concurrency_limit(self.team.organization_id),
- )
- )
+ limiter_stack.enter_context(app_org_concurrency_slot(self.team, task_id=self.query_id))
limiter_stack.enter_context(
get_app_dashboard_queries_rate_limiter().run(
org_id=self.team.organization_id,
diff --git a/posthog/hogql_queries/test/test_query_runner.py b/posthog/hogql_queries/test/test_query_runner.py
index c324d5b88597..37be731ade4f 100644
--- a/posthog/hogql_queries/test/test_query_runner.py
+++ b/posthog/hogql_queries/test/test_query_runner.py
@@ -974,7 +974,7 @@ class TestQueryRunner(BaseTest):
)
elif where == "limiter":
failing = mock.patch(
- "posthog.hogql_queries.query_runner.get_app_org_rate_limiter", side_effect=error_class("over the limit")
+ "posthog.clickhouse.client.limit.get_app_org_rate_limiter", side_effect=error_class("over the limit")
)
elif where == "store":
failing = mock.patch.object(QueryCache, "store_result", side_effect=error_class("cache store failed"))
diff --git a/products/ai_observability/backend/presentation/query_concurrency.py b/products/ai_observability/backend/presentation/query_concurrency.py
index 2dc6d6c46a19..c2b34149161f 100644
--- a/products/ai_observability/backend/presentation/query_concurrency.py
+++ b/products/ai_observability/backend/presentation/query_concurrency.py
@@ -9,9 +9,8 @@ from rest_framework.exceptions import Throttled
from posthog.api.query import CONCURRENCY_LIMIT_USER_MESSAGE
from posthog.clickhouse.client.limit import (
ConcurrencyLimitExceeded,
+ app_org_concurrency_slot,
get_api_team_rate_limiter,
- get_app_org_rate_limiter,
- get_org_app_concurrency_limit,
)
from posthog.clickhouse.query_tagging import get_query_tag_value, is_api_key_access_method
from posthog.constants import AvailableFeature
@@ -38,12 +37,7 @@ def query_concurrency_slots(team: Team) -> Iterator[None]:
team_id=team.pk,
limit=_api_key_concurrency_limit(team) if is_api_key_access else None,
),
- get_app_org_rate_limiter().run(
- org_id=team.organization_id,
- team_id=team.pk,
- is_api=is_api_key_access,
- limit=get_org_app_concurrency_limit(team.organization_id),
- ),
+ app_org_concurrency_slot(team),
):
yield
except ConcurrencyLimitExceeded as error:
diff --git a/products/data_modeling/backend/models/datawarehouse_saved_query.py b/products/data_modeling/backend/models/datawarehouse_saved_query.py
index db39d32700c8..1ec14e51f4bd 100644
--- a/products/data_modeling/backend/models/datawarehouse_saved_query.py
+++ b/products/data_modeling/backend/models/datawarehouse_saved_query.py
@@ -36,7 +36,12 @@ from posthog.hogql.database.s3_table import (
DataWarehouseTable as HogQLDataWarehouseTable,
S3Table,
)
+from posthog.hogql.parser import parse_select
+from posthog.hogql.resolver_utils import extract_select_queries
+from posthog.hogql.visitor import TraversingVisitor
+from posthog.clickhouse.client.limit import app_org_concurrency_slot
+from posthog.clickhouse.query_tagging import Feature, Product, tag_contains_user_hogql, tags_context
from posthog.exceptions_capture import capture_exception
from posthog.models.utils import CreatedMetaFields, DeletedMetaFields, UpdatedMetaFields, UUIDTModel
from posthog.schema_enums import DataWarehouseSavedQueryOrigin
@@ -55,6 +60,28 @@ logger = structlog.get_logger(__name__)
TEST_VIEW_EXPIRY_INTERVAL = timedelta(days=7)
+_IN_SUBQUERY_OPS = (
+ ast.CompareOperationOp.In,
+ ast.CompareOperationOp.NotIn,
+ ast.CompareOperationOp.GlobalIn,
+ ast.CompareOperationOp.GlobalNotIn,
+)
+
+
+def _limit_to_zero_rows(select_query: ast.SelectQuery | ast.SelectSetQuery) -> None:
+ for branch in extract_select_queries(select_query):
+ branch.limit = ast.Constant(value=0)
+ branch.offset = None
+
+
+class _InSubqueryZeroRows(TraversingVisitor):
+ # ClickHouse builds the set of an IN subquery before it plans the outer read, so the outer LIMIT 0
+ # does not stop that read. A scalar subquery keeps its rows, because an empty one is a ClickHouse error.
+ def visit_compare_operation(self, node: ast.CompareOperation) -> None:
+ super().visit_compare_operation(node)
+ if node.op in _IN_SUBQUERY_OPS and isinstance(node.right, ast.SelectQuery | ast.SelectSetQuery):
+ _limit_to_zero_rows(node.right)
+
def validate_saved_query_name(value: str) -> None:
if value == "models":
@@ -463,28 +490,27 @@ class DataWarehouseSavedQuery(CreatedMetaFields, UUIDTModel, UpdatedMetaFields,
self.column_order = list(columns.keys())
def get_columns(self, user: Optional["User"] = None) -> dict[str, dict[str, Any]]:
- from posthog.api.services.query import process_query_dict
- from posthog.clickhouse.query_tagging import Feature, Product, tags_context
- from posthog.hogql_queries.query_runner import ExecutionMode
+ from posthog.hogql.query import execute_hogql_query # noqa: PLC0415 — keeps the heavy dep off the import path
query = self.query or {}
- if not isinstance(query, dict):
+ if not isinstance(query, dict) or "query" not in query:
raise Exception("Saved query is missing a query definition")
- # Saved queries store {"query": "SELECT ..."} without a kind discriminator.
- # process_query_dict requires a valid QuerySchemaRoot, so wrap as HogQLQuery.
- if "kind" not in query and "query" in query:
- query = {"kind": "HogQLQuery", **query}
+ # ClickHouse can still evaluate scalar subqueries before it plans the outer LIMIT 0.
+ select_query = parse_select(query["query"])
+ _limit_to_zero_rows(select_query)
+ _InSubqueryZeroRows().visit(select_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, user=user
- )
- result = getattr(response, "types", [])
+ tag_contains_user_hogql()
+ # Printing the AST back to HogQL text would drop COLUMNS(...) and table column alias lists.
+ with app_org_concurrency_slot(self.team):
+ response = execute_hogql_query(select_query, team=self.team, user=user, query_type="HogQLQuery")
+ result = response.types
- if result is None or isinstance(result, int):
+ if result is None:
raise Exception("No columns types provided by clickhouse in get_columns")
columns = {
diff --git a/products/data_warehouse/backend/models/test/test_saved_query.py b/products/data_warehouse/backend/models/test/test_saved_query.py
index 36636d066109..2b4c3d6cb071 100644
--- a/products/data_warehouse/backend/models/test/test_saved_query.py
+++ b/products/data_warehouse/backend/models/test/test_saved_query.py
@@ -1,11 +1,22 @@
from datetime import timedelta
from types import SimpleNamespace
-from posthog.test.base import BaseTest
+from posthog.test.base import BaseTest, ClickhouseTestMixin
from unittest.mock import patch
from django.db.models.query import QuerySet as DjangoQuerySet
+from parameterized import parameterized
+
+from posthog.schema import CachedHogQLQueryResponse, HogQLQuery
+
+from posthog import redis
+from posthog.clickhouse.client.limit import ConcurrencyLimitExceeded
+from posthog.clickhouse.query_tagging import AccessMethod, Feature, Product, tags_context
+from posthog.constants import AvailableFeature
+from posthog.hogql_queries.hogql_query_runner import HogQLQueryRunner
+from posthog.hogql_queries.query_runner import ExecutionMode
+
from products.data_modeling.backend.facade.modeling import DataWarehouseModelPath
from products.data_modeling.backend.facade.models import DataWarehouseSavedQuery
from products.warehouse_sources.backend.facade.models import DataWarehouseCredential, DataWarehouseTable
@@ -102,8 +113,8 @@ class TestGetColumnsQueryTagging(BaseTest):
feature query tags (enforced as a hard error in DEBUG). Untagged, view creation over any table —
including ai_events — fails with UntaggedQueryError. The inference query must be tagged."""
- @patch("posthog.api.services.query.process_query_dict")
- def test_get_columns_tags_the_inference_query(self, mock_process_query_dict):
+ @patch("posthog.hogql.query.execute_hogql_query")
+ def test_get_columns_tags_the_inference_query(self, mock_execute_hogql_query):
from posthog.clickhouse.query_tagging import Feature, Product, get_query_tags
captured: dict[str, object] = {}
@@ -114,7 +125,7 @@ class TestGetColumnsQueryTagging(BaseTest):
captured["feature"] = tags.feature
return SimpleNamespace(types=[("trace_id", "String")])
- mock_process_query_dict.side_effect = _capture
+ mock_execute_hogql_query.side_effect = _capture
saved_query = DataWarehouseSavedQuery(
team=self.team,
@@ -126,3 +137,97 @@ class TestGetColumnsQueryTagging(BaseTest):
assert captured["product"] == Product.WAREHOUSE
assert captured["feature"] == Feature.DATA_MODELING
assert columns == {"trace_id": {"hogql": "StringDatabaseField", "clickhouse": "String", "valid": True}}
+
+
+class TestGetColumnsConcurrency(BaseTest):
+ @parameterized.expand(
+ [
+ ("browser", None, False),
+ ("oauth", AccessMethod.OAUTH, False),
+ ("api_key", AccessMethod.PERSONAL_API_KEY, True),
+ ]
+ )
+ @patch("posthog.clickhouse.client.limit.TEST", False)
+ def test_shares_the_query_runner_organization_limit(
+ self, _name: str, access_method: AccessMethod | None, is_api_key: bool
+ ) -> None:
+ self.organization.available_product_features = [
+ {"key": AvailableFeature.ORGANIZATION_APP_QUERY_CONCURRENCY_LIMIT, "limit": 1}
+ ]
+ self.organization.save(update_fields=["available_product_features"])
+ self.addCleanup(redis.get_client().delete, f"org_app_concurrency_limit:{self.organization.id}")
+ saved_query = DataWarehouseSavedQuery(team=self.team, name="my_view", query={"query": "SELECT 1 AS value"})
+ column_types = [("value", "UInt8")]
+
+ def infer_while_query_runs(*args: object, **kwargs: object) -> tuple[list[tuple[int]], list[tuple[str, str]]]:
+ with (
+ tags_context(access_method=access_method),
+ patch("posthog.hogql.query.sync_execute", return_value=([], column_types)),
+ ):
+ if is_api_key:
+ columns = saved_query.get_columns(user=self.user)
+ assert columns["value"]["clickhouse"] == "UInt8"
+ else:
+ with self.assertRaises(ConcurrencyLimitExceeded):
+ saved_query.get_columns(user=self.user)
+ return [(1,)], column_types
+
+ runner = HogQLQueryRunner(query=HogQLQuery(query="SELECT 1 AS value"), team=self.team, user=self.user)
+ with (
+ tags_context(product=Product.WAREHOUSE, feature=Feature.QUERY, access_method=None),
+ patch("posthog.hogql.query.sync_execute", side_effect=infer_while_query_runs),
+ ):
+ result = runner.run(execution_mode=ExecutionMode.CALCULATE_BLOCKING_ALWAYS)
+ assert isinstance(result, CachedHogQLQueryResponse)
+ assert result.results == [(1,)]
+
+ with patch("posthog.hogql.query.sync_execute", return_value=([], column_types)):
+ columns = saved_query.get_columns(user=self.user)
+ assert columns["value"]["clickhouse"] == "UInt8"
+
+
+class TestGetColumnsReadsNoRows(ClickhouseTestMixin, BaseTest):
+ @parameterized.expand(
+ [
+ ("aggregation", "SELECT uuid, count() AS n FROM events GROUP BY uuid", {"uuid": "UUID", "n": "UInt64"}),
+ (
+ "existing_limit_and_offset",
+ "SELECT uuid, count() AS n FROM events GROUP BY uuid LIMIT 5 OFFSET 2",
+ {"uuid": "UUID", "n": "UInt64"},
+ ),
+ (
+ "union_all",
+ "SELECT event AS name FROM events UNION ALL SELECT distinct_id AS name FROM events LIMIT 3",
+ {"name": "String"},
+ ),
+ (
+ "in_subquery",
+ "SELECT event FROM events WHERE distinct_id IN (SELECT distinct_id FROM events WHERE event = 'sign up')",
+ {"event": "String"},
+ ),
+ ]
+ )
+ def test_infers_types_without_reading_rows(self, _name: str, sql: str, expected_types: dict[str, str]) -> None:
+ saved_query = DataWarehouseSavedQuery(team=self.team, name="my_view", query={"query": sql})
+
+ with self.capture_select_queries() as queries:
+ columns = saved_query.get_columns(user=self.user)
+
+ assert {name: column["clickhouse"] for name, column in columns.items()} == expected_types
+ assert len(queries) == 1
+ assert queries[0].count("LIMIT 0") == queries[0].count("SELECT")
+ assert "OFFSET" not in queries[0]
+
+ def test_keeps_the_rows_of_a_scalar_subquery(self) -> None:
+ saved_query = DataWarehouseSavedQuery(
+ team=self.team,
+ name="my_view",
+ query={"query": "SELECT event FROM events WHERE timestamp > (SELECT min(timestamp) FROM events)"},
+ )
+
+ with self.capture_select_queries() as queries:
+ columns = saved_query.get_columns(user=self.user)
+
+ assert columns["event"]["clickhouse"] == "String"
+ assert queries[0].count("SELECT") == 2
+ assert queries[0].count("LIMIT 0") == 1
diff --git a/products/marketing_analytics/backend/api.py b/products/marketing_analytics/backend/api.py
index 90f3667d01ec..d4f542d8ffd0 100644
--- a/products/marketing_analytics/backend/api.py
+++ b/products/marketing_analytics/backend/api.py
@@ -45,9 +45,8 @@ from posthog.api.project import capture_team_config_diff
from posthog.api.routing import TeamAndOrgViewSetMixin
from posthog.clickhouse.client.limit import (
ConcurrencyLimitExceeded,
+ app_org_concurrency_slot,
get_api_team_rate_limiter,
- get_app_org_rate_limiter,
- get_org_app_concurrency_limit,
)
from posthog.clickhouse.query_tagging import (
Feature,
@@ -1206,12 +1205,7 @@ class MarketingAnalyticsViewSet(TeamAndOrgViewSetMixin, GenericViewSet):
get_api_team_rate_limiter().run(
team_id=self.team_id, is_api=is_api, limit=runner.get_api_queries_concurrency_limit()
),
- get_app_org_rate_limiter().run(
- org_id=self.team.organization_id,
- team_id=self.team_id,
- is_api=is_api,
- limit=get_org_app_concurrency_limit(self.team.organization_id),
- ),
+ app_org_concurrency_slot(self.team),
):
result = runner.sessions(
goal_id=data["goal_id"],
diff --git a/products/marketing_analytics/backend/services/test_conversion_recordings.py b/products/marketing_analytics/backend/services/test_conversion_recordings.py
index ce52d17d2780..cd3c8325a312 100644
--- a/products/marketing_analytics/backend/services/test_conversion_recordings.py
+++ b/products/marketing_analytics/backend/services/test_conversion_recordings.py
@@ -174,8 +174,11 @@ class TestConversionRecordings(ClickhouseTestMixin, APIBaseTest):
with self.subTest(invalid_fields=invalid_fields):
invalid = self.client.post(url, {**payload, **invalid_fields}, format="json")
self.assertEqual(invalid.status_code, 400)
- for limiter in ("get_app_org_rate_limiter", "get_api_team_rate_limiter"):
- with self.subTest(limiter=limiter), patch(f"products.marketing_analytics.backend.api.{limiter}") as mock:
+ for limiter in (
+ "posthog.clickhouse.client.limit.get_app_org_rate_limiter",
+ "products.marketing_analytics.backend.api.get_api_team_rate_limiter",
+ ):
+ with self.subTest(limiter=limiter), patch(limiter) as mock:
mock.return_value.run.side_effect = ConcurrencyLimitExceeded("internal limiter detail")
throttled = self.client.post(url, payload, format="json")
self.assertEqual(throttled.status_code, 429)
diff --git a/products/product_analytics/backend/hogql_queries/trends/test/__snapshots__/test_trends_data_warehouse_query.ambr b/products/product_analytics/backend/hogql_queries/trends/test/__snapshots__/test_trends_data_warehouse_query.ambr
index a2311a8d6ce8..1eb6eec70c96 100644
--- a/products/product_analytics/backend/hogql_queries/trends/test/__snapshots__/test_trends_data_warehouse_query.ambr
+++ b/products/product_analytics/backend/hogql_queries/trends/test/__snapshots__/test_trends_data_warehouse_query.ambr
@@ -53,20 +53,19 @@
posthog_test_test_table_1.prop_1 AS prop_2,
1 AS boolfield
FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.hogql.datawarehouse.trendquery/posthog_test_test_table_1/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` String, `prop_1` String, `prop_2` String, `created` DateTime64(3, \'UTC\')') AS posthog_test_test_table_1
- LIMIT 101
- OFFSET 0 SETTINGS format_csv_allow_double_quotes=1,
- readonly=2,
- max_execution_time=60,
- allow_experimental_object_type=1,
- max_ast_elements=4000000,
- max_expanded_ast_elements=4000000,
- max_bytes_before_external_group_by=0,
- transform_null_in=1,
- optimize_min_equality_disjunction_chain_length=4294967295,
- optimize_rewrite_aggregate_function_with_if=0,
- optimize_min_inequality_conjunction_chain_length=4294967295,
- allow_experimental_join_condition=1,
- use_hive_partitioning=0
+ LIMIT 0 SETTINGS format_csv_allow_double_quotes=1,
+ readonly=2,
+ max_execution_time=60,
+ allow_experimental_object_type=1,
+ max_ast_elements=4000000,
+ max_expanded_ast_elements=4000000,
+ max_bytes_before_external_group_by=0,
+ transform_null_in=1,
+ optimize_min_equality_disjunction_chain_length=4294967295,
+ optimize_rewrite_aggregate_function_with_if=0,
+ optimize_min_inequality_conjunction_chain_length=4294967295,
+ allow_experimental_join_condition=1,
+ use_hive_partitioning=0
'''
# ---
# name: TestTrendsDataWarehouseQuery.test_trends_breakdown_on_view.1
@@ -128,20 +127,19 @@
posthog_test_test_table_1.prop_1 AS prop_2,
1 AS boolfield
FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.hogql.datawarehouse.trendquery/posthog_test_test_table_1/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` String, `prop_1` String, `prop_2` String, `created` DateTime64(3, \'UTC\')') AS posthog_test_test_table_1
- LIMIT 101
- OFFSET 0 SETTINGS format_csv_allow_double_quotes=1,
- readonly=2,
- max_execution_time=60,
- allow_experimental_object_type=1,
- max_ast_elements=4000000,
- max_expanded_ast_elements=4000000,
- max_bytes_before_external_group_by=0,
- transform_null_in=1,
- optimize_min_equality_disjunction_chain_length=4294967295,
- optimize_rewrite_aggregate_function_with_if=0,
- optimize_min_inequality_conjunction_chain_length=4294967295,
- allow_experimental_join_condition=1,
- use_hive_partitioning=0
+ LIMIT 0 SETTINGS format_csv_allow_double_quotes=1,
+ readonly=2,
+ max_execution_time=60,
+ allow_experimental_object_type=1,
+ max_ast_elements=4000000,
+ max_expanded_ast_elements=4000000,
+ max_bytes_before_external_group_by=0,
+ transform_null_in=1,
+ optimize_min_equality_disjunction_chain_length=4294967295,
+ optimize_rewrite_aggregate_function_with_if=0,
+ optimize_min_inequality_conjunction_chain_length=4294967295,
+ allow_experimental_join_condition=1,
+ use_hive_partitioning=0
'''
# ---
# name: TestTrendsDataWarehouseQuery.test_trends_breakdown_on_view_with_date_timestamp.1
diff --git a/products/product_analytics/backend/tests/test_facade.py b/products/product_analytics/backend/tests/test_facade.py
index 8735b3231407..73ec13a7098b 100644
--- a/products/product_analytics/backend/tests/test_facade.py
+++ b/products/product_analytics/backend/tests/test_facade.py
@@ -156,7 +156,7 @@ class TestRunCachedTrendsQuery(BaseTest):
return_value=response,
),
patch("posthog.hogql_queries.query_runner.get_api_team_rate_limiter") as api_limiter,
- patch("posthog.hogql_queries.query_runner.get_app_org_rate_limiter") as org_limiter,
+ patch("posthog.clickhouse.client.limit.get_app_org_rate_limiter") as org_limiter,
patch(
"products.product_analytics.backend.hogql_queries.trends.trends_query_runner.TrendsQueryRunner._enforce_api_queries_budget"
) as enforce_budget,