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(dashboards): don't commit rejected tile refreshes as empty results (#74717)

Andy Zhaoe7376dab30f6
diff --git a/frontend/src/scenes/dashboard/dashboardLogic.test.ts b/frontend/src/scenes/dashboard/dashboardLogic.test.ts
index 02c10ed42402..0fd599862745 100644
--- a/frontend/src/scenes/dashboard/dashboardLogic.test.ts
+++ b/frontend/src/scenes/dashboard/dashboardLogic.test.ts
@@ -1355,6 +1355,51 @@ describe('dashboardLogic', () => {
})
})
+ it('keeps tile data and marks the tile errored when a refresh terminates in a rejection stub', async () => {
+ const dashboard = dashboards[5]
+ const insight1 = dashboard.tiles[0].insight!
+ const insight2 = dashboard.tiles[1].insight!
+ const resultsBeforeRefresh = logic.values.insightTiles.map((t) => t.insight!.result)
+ expect(resultsBeforeRefresh.every((r) => r != null)).toBe(true)
+
+ // What getInsightWithRetry resolves to when the app-level concurrency limiter (or a
+ // server-side calculation error) rejects every attempt: an insight-shaped payload with
+ // no result and an errored query_status
+ const getInsightWithRetrySpy = jest
+ .spyOn(dashboardUtils, 'getInsightWithRetry')
+ .mockImplementation(async (_teamId, insight) => ({
+ ...insight,
+ result: null,
+ query_status: {
+ id: 'rejected-query',
+ team_id: 2,
+ query_async: true,
+ complete: false,
+ error: true,
+ error_code: null,
+ error_message: 'concurrency_limit_exceeded',
+ },
+ }))
+
+ try {
+ await expectLogic(logic, () => {
+ logic.actions.triggerDashboardRefresh()
+ }).toFinishAllListeners()
+
+ // The stub must not be committed as a successful refresh: tiles keep their data
+ expect(logic.values.insightTiles.map((t) => t.insight!.result)).toEqual(resultsBeforeRefresh)
+ // and surface an error state instead of rendering the null result as an empty insight
+ expect(logic.values.refreshStatus[insight1.short_id]).toEqual(
+ expect.objectContaining({ errored: true })
+ )
+ expect(logic.values.refreshStatus[insight2.short_id]).toEqual(
+ expect.objectContaining({ errored: true })
+ )
+ } finally {
+ getInsightWithRetrySpy.mockRestore()
+ }
+ })
+
it('pins the "X out of Y" denominator when a tile aborts mid-cycle and keeps siblings tracked', async () => {
const dashboard = dashboards[5]
const insight1 = dashboard.tiles[0].insight!
@@ -1802,6 +1847,30 @@ describe('dashboardLogic', () => {
.toDispatchActions(['saveEditModeChanges', 'saveEditModeChangesSuccess', 'refreshDashboardItems'])
.toFinishAllListeners()
})
+
+ it('applying a variable value refreshes every tile with the new value attached to the request', async () => {
+ await mountDashboardWithVariable({})
+
+ const getInsightWithRetrySpy = jest
+ .spyOn(dashboardUtils, 'getInsightWithRetry')
+ .mockImplementation(async (_teamId, insight) => insight)
+
+ try {
+ await expectLogic(logic, () => {
+ logic.actions.overrideVariableValue(variableId, 'applied-value', false)
+ })
+ .toDispatchActions(['overrideVariableValue', 'refreshDashboardItems'])
+ .toFinishAllListeners()
+
+ expect(getInsightWithRetrySpy).toHaveBeenCalledTimes(1)
+ const variablesOverride = getInsightWithRetrySpy.mock.calls[0][7]
+ expect(variablesOverride).toEqual({
+ [variableId]: expect.objectContaining({ code_name: 'organization', value: 'applied-value' }),
+ })
+ } finally {
+ getInsightWithRetrySpy.mockRestore()
+ }
+ })
})
describe('external updates', () => {
diff --git a/frontend/src/scenes/dashboard/dashboardLogic.tsx b/frontend/src/scenes/dashboard/dashboardLogic.tsx
index 975818d5ef2c..f5286fe3d2dd 100644
--- a/frontend/src/scenes/dashboard/dashboardLogic.tsx
+++ b/frontend/src/scenes/dashboard/dashboardLogic.tsx
@@ -137,6 +137,7 @@ import {
getInsightQueryError,
getInsightWithRetry,
isLayoutEditEventSource,
+ isRefreshRejectionStub,
layoutsByTile,
parseURLFilters,
parseURLVariables,
@@ -3526,7 +3527,7 @@ export const dashboardLogic = kea<dashboardLogicType>([
true
)
- if (refreshedInsight) {
+ if (refreshedInsight && !isRefreshRejectionStub(refreshedInsight)) {
const queryError = getInsightQueryError(refreshedInsight)
if (queryError) {
actions.setRefreshError(insight.short_id, queryError)
@@ -3626,7 +3627,7 @@ export const dashboardLogic = kea<dashboardLogicType>([
tile.filters_overrides
)
- if (refreshedInsight) {
+ if (refreshedInsight && !isRefreshRejectionStub(refreshedInsight)) {
const queryError = getInsightQueryError(refreshedInsight)
if (queryError) {
actions.setRefreshError(insight.short_id, queryError)
@@ -3638,7 +3639,6 @@ export const dashboardLogic = kea<dashboardLogicType>([
if (refreshedInsight.is_cached) {
tilesRefreshedCachedCount++
}
-
eventUsageLogic.actions.reportDashboardTileRefreshed(
dashboardId,
tile,
diff --git a/frontend/src/scenes/dashboard/dashboardUtils.ts b/frontend/src/scenes/dashboard/dashboardUtils.ts
index 23050cc539ec..4fbdbbbf41fb 100644
--- a/frontend/src/scenes/dashboard/dashboardUtils.ts
+++ b/frontend/src/scenes/dashboard/dashboardUtils.ts
@@ -177,6 +177,13 @@ export const DEFAULT_AUTO_PREVIEW_TILE_LIMIT = 10
const RATE_LIMIT_ERROR_MESSAGE = 'concurrency_limit_exceeded'
+// A refresh that was rejected (concurrency limit, server-side calculation error) still resolves with an
+// insight-shaped payload: no result, an errored query_status. Committing it to the dashboard would wipe
+// the tile's existing data and render as an empty insight instead of an error.
+export function isRefreshRejectionStub(insight: QueryBasedInsightModel): boolean {
+ return !!insight.query_status?.error && insight.result == null
+}
+
function staleAgeMinutes(effectiveLastRefresh: Dayjs | null): number | null {
if (!effectiveLastRefresh) {
return null