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-warehouse): stop a failed incremental check toasting on the materialization panel (#96786)

Jovan Sakovic44caf6670e43
diff --git a/frontend/src/scenes/data-warehouse/saved_queries/MaterializationStatusPanel.tsx b/frontend/src/scenes/data-warehouse/saved_queries/MaterializationStatusPanel.tsx
index bb62494bb3ec..354117b20dd9 100644
--- a/frontend/src/scenes/data-warehouse/saved_queries/MaterializationStatusPanel.tsx
+++ b/frontend/src/scenes/data-warehouse/saved_queries/MaterializationStatusPanel.tsx
@@ -209,8 +209,12 @@ export function MaterializationStatusPanel({
<div className="flex flex-col flex-1 gap-4">
<div>
<div className="flex flex-row items-center gap-2">
- {!hideTitle && <h3 className="mb-0">Materialization</h3>}
- <LemonTag type="warning">BETA</LemonTag>
+ {!hideTitle && (
+ <>
+ <h3 className="mb-0">Materialization</h3>
+ <LemonTag type="warning">BETA</LemonTag>
+ </>
+ )}
{savedQuery?.latest_error && savedQuery.status === 'Failed' && (
<Tooltip title={savedQuery.latest_error} interactive>
<LemonTag type="danger">Error</LemonTag>
@@ -384,7 +388,7 @@ export function MaterializationStatusPanel({
)}
</div>
</div>
- {incrementalFlagOn && !savedQuery.managed_viewset_kind && (
+ {incrementalFlagOn && !savedQuery.managed_viewset_kind && incrementalCheck && (
<div className="mt-4 max-w-160">
<h4 className="mb-0">Refresh mode</h4>
<IncrementalConfigOptions
diff --git a/frontend/src/scenes/data-warehouse/saved_queries/materializationJobsLogic.test.ts b/frontend/src/scenes/data-warehouse/saved_queries/materializationJobsLogic.test.ts
index c8d89e9397a9..b94e07370787 100644
--- a/frontend/src/scenes/data-warehouse/saved_queries/materializationJobsLogic.test.ts
+++ b/frontend/src/scenes/data-warehouse/saved_queries/materializationJobsLogic.test.ts
@@ -1,4 +1,5 @@
import { expectLogic } from 'kea-test-utils'
+import posthog from 'posthog-js'
import { FEATURE_FLAGS } from 'lib/constants'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
@@ -86,6 +87,40 @@ describe('materializationJobsLogic', () => {
expect(checkCalls).toBe(1)
})
+ // Regression: a rejected eligibility check used to surface as a "Load incremental check failed"
+ // toast on a healthy materialized view. A 4xx is an expected refusal and is not retried; a 5xx is
+ // ours to record, and the next savedQuery reload (every jobs poll) retries it.
+ it.each([
+ [400, { type: 'validation_error', detail: 'Query is not valid.' }, 0, 1],
+ [500, { type: 'server_error', detail: 'Something went wrong.' }, 1, 2],
+ ])(
+ 'treats a %s from the eligibility check as "no incremental option" instead of failing',
+ async (status, body, captured, checksAfterReload) => {
+ const captureException = jest.spyOn(posthog, 'captureException').mockImplementation(() => {})
+ let checkCalls = 0
+ const mocks = apiMocks({ isMaterialized: true })
+ mocks.post = {
+ '/api/environments/:team_id/warehouse_saved_queries/check_incremental/': () => {
+ checkCalls += 1
+ return [status, body]
+ },
+ }
+ useMocks(mocks)
+ logic = materializationJobsLogic({ viewId: 'view-1' })
+ logic.mount()
+
+ await expectLogic(logic)
+ .toDispatchActions(['loadIncrementalCheck', 'loadIncrementalCheckSuccess'])
+ .toNotHaveDispatchedActions(['loadIncrementalCheckFailure'])
+ expect(logic.values.incrementalCheck).toBeNull()
+ expect(captureException).toHaveBeenCalledTimes(captured)
+
+ logic.actions.loadSavedQuery()
+ await expectLogic(logic).toDispatchActions(['loadSavedQuerySuccess']).toFinishAllListeners()
+ expect(checkCalls).toBe(checksAfterReload)
+ }
+ )
+
it.each([
['the surface is an endpoint', { kind: 'endpoint' as const, flag: true }],
['the feature flag is off', { kind: 'view' as const, flag: false }],
diff --git a/frontend/src/scenes/data-warehouse/saved_queries/materializationJobsLogic.ts b/frontend/src/scenes/data-warehouse/saved_queries/materializationJobsLogic.ts
index 17647f86938f..073775fdb41a 100644
--- a/frontend/src/scenes/data-warehouse/saved_queries/materializationJobsLogic.ts
+++ b/frontend/src/scenes/data-warehouse/saved_queries/materializationJobsLogic.ts
@@ -13,10 +13,11 @@ import {
selectors,
} from 'kea'
import { loaders } from 'kea-loaders'
+import posthog from 'posthog-js'
import { lemonToast } from '@posthog/lemon-ui'
-import api, { ApiConfig, PaginatedResponse } from 'lib/api'
+import api, { ApiConfig, ApiError, PaginatedResponse } from 'lib/api'
import { FEATURE_FLAGS } from 'lib/constants'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
@@ -208,7 +209,7 @@ export const materializationJobsLogic = kea<materializationJobsLogicType>([
// doesn't count as the user touching it.
seedIncrementalDraft: (draft: IncrementalConfigDraft) => ({ draft }),
}),
- loaders(({ values, props }) => ({
+ loaders(({ values, props, cache }) => ({
savedQuery: [
null as DataWarehouseSavedQuery | null,
{
@@ -228,7 +229,18 @@ export const materializationJobsLogic = kea<materializationJobsLogicType>([
if (!sql) {
return null
}
- return await api.dataWarehouseSavedQueries.checkIncremental({ query: sql })
+ // A rejected check is not the user's error, so never toast: the panel just omits the
+ // incremental option. A 4xx is a deterministic refusal, so it is not retried. Anything
+ // else is ours to look at, and the next savedQuery reload gets to try again.
+ try {
+ return await api.dataWarehouseSavedQueries.checkIncremental({ query: sql })
+ } catch (e) {
+ if (!(e instanceof ApiError && e.status && e.status >= 400 && e.status < 500)) {
+ posthog.captureException(e)
+ cache.incrementalCheckRequested = false
+ }
+ return null
+ }
},
},
],
diff --git a/frontend/src/scenes/models/NodeDetailScene.tsx b/frontend/src/scenes/models/NodeDetailScene.tsx
index 83266c46ecc2..afac7331919d 100644
--- a/frontend/src/scenes/models/NodeDetailScene.tsx
+++ b/frontend/src/scenes/models/NodeDetailScene.tsx
@@ -1,6 +1,6 @@
import { useValues } from 'kea'
-import { LemonSkeleton } from '@posthog/lemon-ui'
+import { LemonSkeleton, LemonTag } from '@posthog/lemon-ui'
import { AccessDenied } from 'lib/components/AccessDenied'
import { NotFound } from 'lib/components/NotFound'
@@ -37,6 +37,21 @@ const TAB_LABELS: Record<NodeDetailSceneTab, string> = {
tests: 'Tests',
}
+function tabLabel(tab: NodeDetailSceneTab, savedQueryId: string | null | undefined): JSX.Element | string {
+ if (tab === 'tests' && savedQueryId) {
+ return <NodeDetailTestsTabLabel subjectId={savedQueryId} />
+ }
+ if (tab === 'materialization') {
+ return (
+ <span className="flex items-center gap-1">
+ {TAB_LABELS[tab]}
+ <LemonTag type="warning">BETA</LemonTag>
+ </span>
+ )
+ }
+ return TAB_LABELS[tab]
+}
+
export function NodeDetailScene({ id }: NodeDetailSceneLogicProps): JSX.Element {
const { node, nodeLoading, availableTabs, effectiveTab, visitedTabs } = useValues(nodeDetailSceneLogic({ id }))
@@ -76,7 +91,7 @@ export function NodeDetailScene({ id }: NodeDetailSceneLogicProps): JSX.Element
const tabs: LemonTab<NodeDetailSceneTab>[] = availableTabs.map((tab) => ({
key: tab,
- label: tab === 'tests' && savedQueryId ? <NodeDetailTestsTabLabel subjectId={savedQueryId} /> : TAB_LABELS[tab],
+ label: tabLabel(tab, savedQueryId),
link: urls.nodeDetail(id, tab),
'data-attr': `node-detail-${tab}-tab`,
}))
diff --git a/products/data_warehouse/backend/presentation/views/saved_query.py b/products/data_warehouse/backend/presentation/views/saved_query.py
index 4c93aaa3f4ba..daef6ce5c1cc 100644
--- a/products/data_warehouse/backend/presentation/views/saved_query.py
+++ b/products/data_warehouse/backend/presentation/views/saved_query.py
@@ -1449,12 +1449,6 @@ class IncrementalEligibilitySerializer(serializers.Serializer):
)
-# Same bound other SQL-accepting endpoints put on caller-supplied queries (see
-# `posthog/api/query_performance_proxy.py`): parsing runs synchronously on an API worker, so the
-# body has to be capped before it reaches the parser.
-CHECK_INCREMENTAL_MAX_QUERY_LENGTH = 64 * 1024
-
-
class CheckIncrementalThrottle(PersonalApiKeyOrUserRateThrottle):
"""check_incremental parses caller-supplied SQL synchronously on a read scope. The editor calls
it on a debounce, so a per-caller budget far above typing speed only stops scripted floods of
@@ -1464,6 +1458,11 @@ class CheckIncrementalThrottle(PersonalApiKeyOrUserRateThrottle):
rate = "120/minute"
+# The check parses synchronously on an API worker. The bound keeps a scripted flood of large bodies
+# from tying up workers while sitting well above any view the editor produces.
+CHECK_INCREMENTAL_MAX_QUERY_LENGTH = 256 * 1024
+
+
class CheckIncrementalSerializer(serializers.Serializer):
"""Body of the `check_incremental` action: a query and an optional config to check it against."""
diff --git a/products/data_warehouse/backend/tests/api/test_saved_query_incremental.py b/products/data_warehouse/backend/tests/api/test_saved_query_incremental.py
index 1934c0447188..734813aebd9c 100644
--- a/products/data_warehouse/backend/tests/api/test_saved_query_incremental.py
+++ b/products/data_warehouse/backend/tests/api/test_saved_query_incremental.py
@@ -3,6 +3,7 @@ from unittest.mock import AsyncMock, patch
from products.data_modeling.backend.facade.models import DataWarehouseSavedQuery
from products.data_warehouse.backend.presentation.views.saved_query import (
+ CHECK_INCREMENTAL_MAX_QUERY_LENGTH,
CheckIncrementalThrottle,
DataWarehouseSavedQueryViewSet,
)
@@ -115,7 +116,8 @@ class TestSavedQueryIncremental(APIBaseTest):
def test_check_incremental_rejects_an_oversized_query(self):
# Parsing runs synchronously on an API worker, so the body has to be bounded before it
# reaches the parser.
- response = self.client.post(self._url("check_incremental/"), {"query": "SELECT 1 -- " + "x" * (64 * 1024)})
+ oversized = "SELECT 1 -- " + "x" * CHECK_INCREMENTAL_MAX_QUERY_LENGTH
+ response = self.client.post(self._url("check_incremental/"), {"query": oversized})
assert response.status_code == 400
assert response.json()["attr"] == "query"
diff --git a/products/data_warehouse/frontend/generated/api.schemas.ts b/products/data_warehouse/frontend/generated/api.schemas.ts
index bda353a851c8..bf1bb57d1326 100644
--- a/products/data_warehouse/frontend/generated/api.schemas.ts
+++ b/products/data_warehouse/frontend/generated/api.schemas.ts
@@ -1716,7 +1716,7 @@ export interface SavedQueryRunApi {
export interface CheckIncrementalApi {
/**
* The HogQL query to check.
- * @maxLength 65536
+ * @maxLength 262144
*/
query: string
/**
diff --git a/products/data_warehouse/frontend/generated/api.zod.ts b/products/data_warehouse/frontend/generated/api.zod.ts
index 1582617345ab..60a96e718a93 100644
--- a/products/data_warehouse/frontend/generated/api.zod.ts
+++ b/products/data_warehouse/frontend/generated/api.zod.ts
@@ -1016,7 +1016,7 @@ export const WarehouseSavedQueriesRunCreateBody = /* @__PURE__ */ zod
* Parses the SQL only, so it is cheap enough to call from the editor as the user types. Lets
* the editor explain why the incremental option is unavailable before anything is saved.
*/
-export const warehouseSavedQueriesCheckIncrementalCreateBodyQueryMax = 65536
+export const warehouseSavedQueriesCheckIncrementalCreateBodyQueryMax = 262144
export const warehouseSavedQueriesCheckIncrementalCreateBodyLookbackSecondsMin = 0
export const warehouseSavedQueriesCheckIncrementalCreateBodyLookbackSecondsMax = 2592000
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index a777ce2e9b60..966deb4f6d61 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -17838,7 +17838,7 @@ export namespace Schemas {
export interface CheckIncremental {
/**
* The HogQL query to check.
- * @maxLength 65536
+ * @maxLength 262144
*/
query: string;
/**