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): clarify saved query activity history (#102842)

Jovan Sakovic8073e74ca1bb
diff --git a/frontend/src/scenes/data-warehouse/saved_queries/activityDescriptions.test.tsx b/frontend/src/scenes/data-warehouse/saved_queries/activityDescriptions.test.tsx
new file mode 100644
index 000000000000..3b33147283cb
--- /dev/null
+++ b/frontend/src/scenes/data-warehouse/saved_queries/activityDescriptions.test.tsx
@@ -0,0 +1,89 @@
+import { render } from '@testing-library/react'
+
+import { ActivityChange, ActivityLogItem } from 'lib/components/ActivityLog/humanizeActivity'
+
+import { initKeaTests } from '~/test/init'
+import { ActivityScope } from '~/types'
+
+import { dataWarehouseSavedQueryActivityDescriber } from './activityDescriptions'
+
+function describeText(changes: ActivityChange[]): string {
+ const logItem: ActivityLogItem = {
+ user: { first_name: 'Max', last_name: 'Hog', email: '[email protected]' },
+ activity: 'updated',
+ created_at: '2026-03-01T00:00:00Z',
+ scope: ActivityScope.DATA_WAREHOUSE_SAVED_QUERY,
+ item_id: '7',
+ detail: { name: 'daily view', changes, merge: null, trigger: null },
+ }
+ const { description } = dataWarehouseSavedQueryActivityDescriber(logItem)
+ const { container } = render(<>{description}</>)
+ return container.textContent ?? ''
+}
+
+const change = (field: string, before: unknown, after: unknown): ActivityChange => ({
+ type: ActivityScope.DATA_WAREHOUSE_SAVED_QUERY,
+ action: 'changed',
+ field,
+ before: before as ActivityChange['before'],
+ after: after as ActivityChange['after'],
+})
+
+describe('dataWarehouseSavedQueryActivityDescriber', () => {
+ beforeEach(() => {
+ initKeaTests()
+ })
+
+ it.each([
+ ['column_order', ['id', 'name'], ['name', 'id'], 'reordered 2 columns'],
+ ['folder', null, 'folder-1', 'moved the view to the folder-1 folder'],
+ ['folder', 'folder-1', null, 'removed the view from its folder'],
+ ['is_test', false, true, 'marked the view as a test view'],
+ ['is_test', true, false, 'unmarked the view as a test view'],
+ ['new_field', 'before', 'after', 'changed new field'],
+ ])('describes %s changes', (field, before, after, expected) => {
+ expect(describeText([change(field, before, after)])).toContain(expected)
+ })
+
+ it.each([
+ [
+ null,
+ { enabled: true, incremental_key: 'day', unique_key: ['id'], lookback_seconds: 3600 },
+ 'enabled incremental materialization with incremental key day, unique key id, lookback 1 hour',
+ ],
+ [{}, { enabled: true, incremental_key: 'day' }, 'enabled incremental materialization'],
+ [
+ { enabled: true, incremental_key: 'day', unique_key: ['id'], lookback_seconds: 3600 },
+ null,
+ 'disabled incremental materialization',
+ ],
+ [{ enabled: true, incremental_key: 'day' }, {}, 'disabled incremental materialization'],
+ [
+ { enabled: true, incremental_key: 'day', unique_key: ['id'] },
+ { enabled: false, incremental_key: 'day', unique_key: ['id'] },
+ 'disabled incremental materialization',
+ ],
+ [
+ { enabled: false, incremental_key: 'day', unique_key: ['id'] },
+ { enabled: true, incremental_key: 'day', unique_key: ['id'] },
+ 'enabled incremental materialization with incremental key day, unique key id',
+ ],
+ [
+ { enabled: true, incremental_key: 'day', lookback_seconds: 3600 },
+ { enabled: true, incremental_key: 'hour', lookback_seconds: 7200 },
+ 'updated incremental materialization settings: incremental key from day to hour, lookback from 1 hour to 2 hours',
+ ],
+ ])('describes incremental materialization transitions', (before, after, expected) => {
+ expect(describeText([change('incremental_config', before, after)])).toContain(expected)
+ })
+
+ it('keeps the existing activity branches', () => {
+ expect(describeText([change('sync_frequency_interval', '0:01:00', '1:00:00')])).toContain(
+ 'changed sync frequency from 1 minute to 1 hour'
+ )
+ expect(describeText([change('is_materialized', false, true)])).toContain('enabled materialization')
+ expect(describeText([change('query', { query: 'SELECT 1' }, { query: 'SELECT 2' })])).toContain(
+ 'updated the query'
+ )
+ })
+})
diff --git a/frontend/src/scenes/data-warehouse/saved_queries/activityDescriptions.tsx b/frontend/src/scenes/data-warehouse/saved_queries/activityDescriptions.tsx
index 2c6b4b534e88..b16c37628de4 100644
--- a/frontend/src/scenes/data-warehouse/saved_queries/activityDescriptions.tsx
+++ b/frontend/src/scenes/data-warehouse/saved_queries/activityDescriptions.tsx
@@ -31,6 +31,94 @@ function humanizeInterval(raw: string | null | undefined): string {
return buckets[raw] ?? raw
}
+function humanizeLookback(raw: unknown): string {
+ if (typeof raw !== 'number' || raw <= 0) {
+ return 'none'
+ }
+ if (raw % 86400 === 0) {
+ const days = raw / 86400
+ return `${days} day${days === 1 ? '' : 's'}`
+ }
+ if (raw % 3600 === 0) {
+ const hours = raw / 3600
+ return `${hours} hour${hours === 1 ? '' : 's'}`
+ }
+ if (raw % 60 === 0) {
+ const minutes = raw / 60
+ return `${minutes} minute${minutes === 1 ? '' : 's'}`
+ }
+ return `${raw} seconds`
+}
+
+// `enabled` is what the backend reads in `get_incremental_config`, so a stored config that still
+// carries keys but has `enabled: false` is off.
+function isIncrementalEnabled(config: unknown): boolean {
+ return (
+ typeof config === 'object' &&
+ config !== null &&
+ !Array.isArray(config) &&
+ !!(config as Record<string, unknown>).enabled
+ )
+}
+
+function incrementalSettingLabel(field: string): string {
+ return (
+ {
+ incremental_key: 'incremental key',
+ unique_key: 'unique key',
+ lookback_seconds: 'lookback',
+ }[field] ?? field.replaceAll('_', ' ')
+ )
+}
+
+function formatIncrementalSetting(field: string, value: unknown): string {
+ if (field === 'lookback_seconds') {
+ return humanizeLookback(value)
+ }
+ if (Array.isArray(value)) {
+ return value.length > 0 ? value.join(', ') : 'none'
+ }
+ return value == null || value === '' ? 'none' : String(value)
+}
+
+function describeIncrementalConfig(change: ActivityChange): JSX.Element {
+ const before = change.before
+ const after = change.after
+
+ if (!isIncrementalEnabled(before) && isIncrementalEnabled(after)) {
+ const config = after as Record<string, unknown>
+ const settings = ['incremental_key', 'unique_key', 'lookback_seconds']
+ .filter((field) => config[field] !== undefined)
+ .map((field) => `${incrementalSettingLabel(field)} ${formatIncrementalSetting(field, config[field])}`)
+ return (
+ <>
+ enabled incremental materialization
+ {settings.length > 0 ? <> with {settings.join(', ')}</> : null}
+ </>
+ )
+ }
+
+ if (isIncrementalEnabled(before) && !isIncrementalEnabled(after)) {
+ return <>disabled incremental materialization</>
+ }
+
+ const beforeConfig = (before ?? {}) as Record<string, unknown>
+ const afterConfig = (after ?? {}) as Record<string, unknown>
+ const changedSettings = ['incremental_key', 'unique_key', 'lookback_seconds'].filter(
+ (field) => JSON.stringify(beforeConfig[field]) !== JSON.stringify(afterConfig[field])
+ )
+ const changes = changedSettings.map(
+ (field) =>
+ `${incrementalSettingLabel(field)} from ${formatIncrementalSetting(field, beforeConfig[field])} to ${formatIncrementalSetting(field, afterConfig[field])}`
+ )
+
+ return <>updated incremental materialization settings{changes.length > 0 ? <>: {changes.join(', ')}</> : null}</>
+}
+
+function humanizeField(field: string | undefined): string {
+ return (field ?? 'unknown field').replaceAll('_', ' ')
+}
+
function describeChange(change: ActivityChange): JSX.Element | null {
if (change.field === 'sync_frequency_interval') {
const before = humanizeInterval(change.before as string | null)
@@ -47,7 +135,28 @@ function describeChange(change: ActivityChange): JSX.Element | null {
if (change.field === 'query') {
return <>updated the query</>
}
- return <>changed {change.field}</>
+ if (change.field === 'column_order') {
+ const count = Array.isArray(change.after) ? change.after.length : undefined
+ return <>{count ? `reordered ${count} columns` : <>reordered columns</>}</>
+ }
+ if (change.field === 'incremental_config') {
+ return describeIncrementalConfig(change)
+ }
+ if (change.field === 'folder') {
+ const folder = change.after == null ? null : String(change.after)
+ if (!folder) {
+ return <>removed the view from its folder</>
+ }
+ return (
+ <>
+ moved the view to the <strong>{folder}</strong> folder
+ </>
+ )
+ }
+ if (change.field === 'is_test') {
+ return change.after ? <>marked the view as a test view</> : <>unmarked the view as a test view</>
+ }
+ return <>changed {humanizeField(change.field)}</>
}
export function dataWarehouseSavedQueryActivityDescriber(
diff --git a/posthog/models/activity_logging/activity_log.py b/posthog/models/activity_logging/activity_log.py
index 6ea64395387f..b5a31d59b75c 100644
--- a/posthog/models/activity_logging/activity_log.py
+++ b/posthog/models/activity_logging/activity_log.py
@@ -779,6 +779,12 @@ field_exclusions: dict[AuditableScope, list[str]] = {
"last_run_at",
"latest_error",
"deleted_name",
+ "table",
+ "managed_viewset",
+ "origin",
+ "expires_at",
+ "incremental_state",
+ "semantic_enrichment_hash",
],
"Endpoint": [
"saved_query",