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.

feat(bi): retain catalog metric trust context (#124960)

Marius Andraeacb0f1cffe5
diff --git a/docs/published/handbook/engineering/data-warehouse.md b/docs/published/handbook/engineering/data-warehouse.md
index 2f4b3c54375a..63e6a000218f 100644
--- a/docs/published/handbook/engineering/data-warehouse.md
+++ b/docs/published/handbook/engineering/data-warehouse.md
@@ -435,7 +435,7 @@ Implementation audit, October 28, 2026. These are proposed integration contracts
### BI-owned integration work
- [x] Adopt the catalog overwrite-confirmation flow for worksheet metric proposals. Preserve entered values on cancel, allow retry, and keep overwritten metrics proposed.
-- [ ] Show catalog trust context when exploring a metric: approval and drift status, unit, owner, and stable identity. Distinguish the copied definition from current catalog state; never imply a snapshot follows catalog changes.
+- [x] Show catalog trust context when exploring a metric: approval and drift status, unit, owner, and stable identity. Saved copies retain metadata from copy time, labeled **Catalog status when copied (unverified)** without positive approval styling. Only Proposed and Approved statuses are recorded. Older copies explicitly say no status was recorded. The metadata is editable worksheet content, not verified provenance or a live approval; authors are directed to the current catalog entry. Live version checks remain shared-layer work.
- [ ] Add deliberate, searchable metric discovery in BI using the existing catalog search API. Handle loading, failure, no matches, pagination, and unsupported definition kinds explicitly.
- [ ] Surface existing field descriptions and data-quality context in the data pane. Preserve raw field identities and distinguish certification from current check health.
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 0cdb1e443a8f..1173d0baf8d3 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -6738,6 +6738,22 @@ snapshots:
hash: v1.k794b7964.685e595b2d82e74d28e617318f7ab37134911236fe466774afd1d226973032c8.W4MK1HnWdy6MWAiwx5r9tbBjfoDjCeHmfEBHofnhsYc
products-business-intelligence-dashboard-filter-bar--quill--light:
hash: v1.k794b7964.c62c158d76af1654b660d3d06e658d279edbc27a2c4887574d2c94206ce8eca7.1bXevOAdN31g-PzyVyWxCY5d8UwJKMv5T2FJ6Sv12K8
+ products-business-intelligence-metric-snapshot-context--approved--dark:
+ hash: v1.k794b7964.e06e7ad1816712c77e949076db6d7dc3304ba9a7f2ea1b1a7e803708237d02ba.uP6ib1f3_nRW7cv7cGYnn8Jde39lRzbs1MGDXMHVMd4
+ products-business-intelligence-metric-snapshot-context--approved--light:
+ hash: v1.k794b7964.75192b1e25053e039761ad2d525bb407012884a1d98323dd5318295e5478fd05.2DP6-4ihQV6hTrS8bFgTGTeMTnyFVV4jyp1DRkC6tGE
+ products-business-intelligence-metric-snapshot-context--drifted--dark:
+ hash: v1.k794b7964.9c989669da728c2691e18d162f0afb2fe308094449b68f232440fc799d7542c9.cNdzMfWqj39FjNOpC95r0XmlZ3wnFj3SHP1NhM7tXTA
+ products-business-intelligence-metric-snapshot-context--drifted--light:
+ hash: v1.k794b7964.f90e05112efecb61d341c0c1b795fac5fb8b633feb0dee221ec6a0f2c1e1fd6f.K3tM4EWkIvxTAOThCbXaPk6MXGlV6lFW6mEFNAYoeAI
+ products-business-intelligence-metric-snapshot-context--legacy--dark:
+ hash: v1.k794b7964.02cb30f2a9f5412ee52344dcaaac4376afacf0f579f54f47d758a64e5baefc52.Pd4bHTeTRnZXdzQJ-1wg_9Dk-Yy7DyMX80nb4Z0ywhY
+ products-business-intelligence-metric-snapshot-context--legacy--light:
+ hash: v1.k794b7964.d6d27f0ef9ca400405806c6f6ace47d1060bcf5a0b5681067c6513ad681e51dd.FfbYMprVLi1Orc2Ylpp5_mUlvfXkrmxwLY1jhNy50vA
+ products-business-intelligence-metric-snapshot-context--proposed--dark:
+ hash: v1.k794b7964.9c989669da728c2691e18d162f0afb2fe308094449b68f232440fc799d7542c9.lLOhFgjZEnq-nG_Djv9Vnx--xzxtQfB6ELO4KfVKXow
+ products-business-intelligence-metric-snapshot-context--proposed--light:
+ hash: v1.k794b7964.f90e05112efecb61d341c0c1b795fac5fb8b633feb0dee221ec6a0f2c1e1fd6f.QHGWgQX5pi-FN6VMPjdDfAFgbfq7cbptsTiFfzC_09E
products-business-intelligence-pivot-table--conditional-formatting--dark:
hash: v1.k794b7964.8647a315842a7e58e16b9597686a037f51fca27b39cc31a86364531342f0de2d.KI6_i9LRgw64b1jPz_P-_1ghk-QlxGRt8OphgQTyh6o
products-business-intelligence-pivot-table--conditional-formatting--light:
@@ -6775,9 +6791,9 @@ snapshots:
products-business-intelligence-scatter--read-only--light:
hash: v1.k794b7964.21cf4e3c6d31ac5d3653d176f876dbec5894d2569bd082e4fc5117a7dbe40af3.b-Dnoj2QTxOlUnZTMZuBqQGvSNk2lnMS0V6wnY_Aud0
products-business-intelligence-worksheet-exploration--catalog-metric-parameters--dark:
- hash: v1.k794b7964.e4aba5a02b47ed60fee15aad80c85c441ace3ccb5d3b01588d3de6e400d1bc6a.vaAwhvGpZJ-YzoLfr5lXDawVlMY26mqYT9GWz58BG4g
+ hash: v1.k794b7964.8fefa0b4720ec5e2a555da632ceb950910aa46fd16a7bd1d40111ddb331ee3ad.ksRj5txXEFCxPL705jBaTN7m1rUiLBFrJkz3pE0Kq6s
products-business-intelligence-worksheet-exploration--catalog-metric-parameters--light:
- hash: v1.k794b7964.c7f82a1b856cd680d7abcdc083c4c867aa5053e375e4ccb25bc79d4d7f7e6467.ZADdvcly-pakRpNSnbtLMw-J0ihLOb2LsLtrhwZGmDY
+ hash: v1.k794b7964.3d835f8d2d123537f256fa78c15b5b53d7bec10c06b83503bccb3f5462bce890.x9wCxcsEYjfREmMztPbCBtj4MvrrZbFtlujY3Ve5qU8
products-business-intelligence-worksheet-exploration--daily-1500-groups--dark:
hash: v1.k794b7964.2016a21a055e190a89fe3bb674de641d8841a050204b3646a1052ae00a201a4e.91mWPEAqeMveO3bjutJW2uDvY6aYHdP20UTJpLWZRjc
products-business-intelligence-worksheet-exploration--daily-1500-groups--light:
@@ -10671,9 +10687,9 @@ snapshots:
scenes-app-data-warehouse-sql-editor--bi-calculated-measure-editor--light:
hash: v1.k794b7964.c9e9cf295cbfb0aa5228652d2fcde7a616bdbc45406120442f61a57616b3ac1c.hxQqmOmxq6w9FrhKZBKKUhrsjTmOqmcP1p-wXdkO6Go
scenes-app-data-warehouse-sql-editor--bi-catalog-snapshot--dark:
- hash: v1.k794b7964.3bab191ca654373affb2a2ff0e9fd186102376d247f882ad5e6e11c0a433571b.X2uMCRABz2YNnmzlS4zVq_Z7VbrFwQZ52B33Chp8CTo
+ hash: v1.k794b7964.1a004c30a95345c3df693f0fd766ceb83c03c265ef8bb835512cde4f0f40ce6c.GtH81wJ-N5qNO_4PDrLWKH5z-QMMd9qbdr9Gg4RlJTE
scenes-app-data-warehouse-sql-editor--bi-catalog-snapshot--light:
- hash: v1.k794b7964.cee3fd95c7cdabb29d773cf26a06a7e0830e229ba5f13f1996bd981d69bffaa8._dYoW7AVF_leqUuIs_lnnWD8Aaw3VKI-Xp5mc2XhTNQ
+ hash: v1.k794b7964.5e7c2e0d219aca99787c1d617be5f849a41c9feda76e6ccd5b11d146433365a9.UYWuJ5yxrtBgfAyyVz2fIfoq5S47AcFLUSm-Le6-p9I
scenes-app-data-warehouse-sql-editor--bi-catalog-source--dark:
hash: v1.k794b7964.7db47de6204c734f634f14500a32ad50c79ba78b0ed3c1f8d0204806f9ee7062.cpAWrZVLUPNbk5Vgw6j7FNZgvAzdLNKdg8HMSh-eHrw
scenes-app-data-warehouse-sql-editor--bi-catalog-source--light:
diff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.json
index 244d2e082906..3ffb3df17f63 100644
--- a/frontend/src/queries/schema.json
+++ b/frontend/src/queries/schema.json
@@ -6222,6 +6222,10 @@
"enum": ["count", "count_distinct", "sum", "average", "minimum", "maximum", "custom"],
"type": "string"
},
+ "BICatalogMetricStatus": {
+ "enum": ["approved", "proposed"],
+ "type": "string"
+ },
"BICategoryGroup": {
"additionalProperties": false,
"properties": {
@@ -6268,6 +6272,32 @@
"description": "Catalog provenance only: the snapshot does not track subsequent definition edits.",
"type": "string"
},
+ "catalogMetricContext": {
+ "additionalProperties": false,
+ "description": "Catalog metadata at copy time, not a live approval of the worksheet.",
+ "properties": {
+ "id": {
+ "type": "string"
+ },
+ "isDrifted": {
+ "type": "boolean"
+ },
+ "owner": {
+ "type": ["string", "null"]
+ },
+ "status": {
+ "$ref": "#/definitions/BICatalogMetricStatus"
+ },
+ "unit": {
+ "type": "string"
+ },
+ "updatedAt": {
+ "type": ["string", "null"]
+ }
+ },
+ "required": ["id", "status", "isDrifted", "unit", "owner", "updatedAt"],
+ "type": "object"
+ },
"chartType": {
"$ref": "#/definitions/ChartDisplayType"
},
diff --git a/frontend/src/queries/schema/schema-business-intelligence.ts b/frontend/src/queries/schema/schema-business-intelligence.ts
index 13258f4278b7..13acb03621ca 100644
--- a/frontend/src/queries/schema/schema-business-intelligence.ts
+++ b/frontend/src/queries/schema/schema-business-intelligence.ts
@@ -31,6 +31,8 @@ export type BIQueryLimit = 100 | 1000 | 10000 | 50000
export type BISortDirection = 'asc' | 'desc'
+export type BICatalogMetricStatus = 'approved' | 'proposed'
+
export interface BISort {
key: string
direction: BISortDirection
@@ -154,6 +156,15 @@ export interface BIConfig {
querySnapshot?: HogQLQuery
/** Catalog provenance only: the snapshot does not track subsequent definition edits. */
catalogMetric?: string
+ /** Catalog metadata at copy time, not a live approval of the worksheet. */
+ catalogMetricContext?: {
+ id: string
+ status: BICatalogMetricStatus
+ isDrifted: boolean
+ unit: string
+ owner: string | null
+ updatedAt: string | null
+ }
/** Reusable expressions owned by this worksheet only. */
localFields?: BIField[]
/** Named dimension sequences saved with the worksheet; imports are independent copies. */
diff --git a/frontend/src/scenes/data-warehouse/editor/SQLEditorScene.stories.tsx b/frontend/src/scenes/data-warehouse/editor/SQLEditorScene.stories.tsx
index 2f80543f0512..5665fdc9ed2c 100644
--- a/frontend/src/scenes/data-warehouse/editor/SQLEditorScene.stories.tsx
+++ b/frontend/src/scenes/data-warehouse/editor/SQLEditorScene.stories.tsx
@@ -1910,7 +1910,7 @@ export const BICatalogSnapshot: Story = {
},
play: async ({ canvasElement }) => {
const canvas = within(canvasElement)
- await canvas.findByRole('link', { name: 'View catalog definition' }, { timeout: 15000 })
+ await canvas.findByRole('link', { name: 'View current catalog entry' }, { timeout: 15000 })
await userEvent.click(await canvas.findByRole('button', { name: 'Run worksheet' }))
await expect(canvas.findByText('450', { exact: true })).resolves.toBeVisible()
},
diff --git a/posthog/schema.py b/posthog/schema.py
index 0a56df74cda9..3616bf101bae 100644
--- a/posthog/schema.py
+++ b/posthog/schema.py
@@ -61,6 +61,7 @@ from posthog.schema_enums import (
BaseMathType as BaseMathType,
BehavioralEventSource as BehavioralEventSource,
BIAggregation as BIAggregation,
+ BICatalogMetricStatus as BICatalogMetricStatus,
BIDateBucket as BIDateBucket,
BIFilterOperator as BIFilterOperator,
BillingSpendResponseBreakdownType as BillingSpendResponseBreakdownType,
@@ -989,6 +990,18 @@ class BIConditionGroup(BaseModel):
operator: Operator1
+class CatalogMetricContext(BaseModel):
+ model_config = ConfigDict(
+ extra="forbid",
+ )
+ id: str
+ isDrifted: bool
+ owner: str | None = None
+ status: BICatalogMetricStatus
+ unit: str
+ updatedAt: str | None = None
+
+
class Alias(BaseModel):
model_config = ConfigDict(
extra="forbid",
@@ -31653,6 +31666,10 @@ class BIConfig(BaseModel):
default=None,
description=("Catalog provenance only: the snapshot does not track subsequent definition edits."),
)
+ catalogMetricContext: CatalogMetricContext | None = Field(
+ default=None,
+ description=("Catalog metadata at copy time, not a live approval of the worksheet."),
+ )
chartType: ChartDisplayType
colorBy: str | None = None
columns: list[BIField]
diff --git a/posthog/schema_enums.py b/posthog/schema_enums.py
index 47adbe78968b..6bfbd27dc987 100644
--- a/posthog/schema_enums.py
+++ b/posthog/schema_enums.py
@@ -661,6 +661,11 @@ class BIAggregation(StrEnum):
CUSTOM = "custom"
+class BICatalogMetricStatus(StrEnum):
+ APPROVED = "approved"
+ PROPOSED = "proposed"
+
+
class Operator1(StrEnum):
AND_ = "AND"
OR_ = "OR"
diff --git a/products/business_intelligence/frontend/BIEditor.tsx b/products/business_intelligence/frontend/BIEditor.tsx
index b08fda6238b6..ba0effe9236d 100644
--- a/products/business_intelligence/frontend/BIEditor.tsx
+++ b/products/business_intelligence/frontend/BIEditor.tsx
@@ -2,12 +2,11 @@ import { BindLogic, useActions, useValues } from 'kea'
import { useRef, type ReactNode, type Ref } from 'react'
import { IconX } from '@posthog/icons'
-import { LemonBanner, LemonButton, LemonTag, Link } from '@posthog/lemon-ui'
+import { LemonButton, LemonTag } from '@posthog/lemon-ui'
import { Resizer } from 'lib/components/Resizer/Resizer'
import { resizerLogic, ResizerLogicProps } from 'lib/components/Resizer/resizerLogic'
import { IconTableChart } from 'lib/lemon-ui/icons'
-import { urls } from 'scenes/urls'
import { BICalculatedMeasureModal } from 'products/business_intelligence/frontend/BICalculatedMeasureModal'
import { biEditorLogic } from 'products/business_intelligence/frontend/biEditorLogic'
@@ -28,6 +27,7 @@ import { BILocalFieldModal } from './BILocalFieldModal'
import { BIMeasureSettingsModal } from './BIMeasureSettingsModal'
import { biMetricParametersLogic, metricParameterDrafts } from './biMetricParametersLogic'
import { BIMetricParametersModal } from './BIMetricParametersModal'
+import { BIMetricSnapshotContext } from './BIMetricSnapshotContext'
export function BIEditor({
tabId,
@@ -91,16 +91,7 @@ export function BIEditor({
return (
<BindLogic logic={biEditorLogic} props={{ tabId }}>
<div className="@container/bi-editor flex min-h-0 flex-1 flex-col" data-attr="bi-catalog-snapshot">
- <LemonBanner type="info" dismissKey="bi-query-snapshot">
- This is a SQL copy.{' '}
- {hasMetricParameters
- ? 'Edit its parameters below, or use View SQL to change the query.'
- : 'Use View SQL to edit its dates or grouping in the SQL editor.'}{' '}
- Catalog changes won't update this copy.{' '}
- {config.catalogMetric && (
- <Link to={urls.dataCatalogMetric(config.catalogMetric)}>View catalog definition</Link>
- )}
- </LemonBanner>
+ <BIMetricSnapshotContext config={config} />
{hasMetricParameters && (
<div className="p-2">
<LemonButton type="secondary" onClick={openMetricParameters}>
diff --git a/products/business_intelligence/frontend/BIMetricSnapshotContext.stories.tsx b/products/business_intelligence/frontend/BIMetricSnapshotContext.stories.tsx
new file mode 100644
index 000000000000..e533dc5c9bba
--- /dev/null
+++ b/products/business_intelligence/frontend/BIMetricSnapshotContext.stories.tsx
@@ -0,0 +1,32 @@
+import { Meta, StoryObj } from '@storybook/react'
+
+import { NodeKind } from '~/queries/schema/schema-general'
+
+import { catalogMetricWorksheet } from './biCatalog'
+import { BIMetricSnapshotContext } from './BIMetricSnapshotContext'
+
+const config = catalogMetricWorksheet({
+ id: 'example-revenue',
+ name: 'revenue',
+ status: 'approved',
+ is_drifted: false,
+ unit: 'usd',
+ owner: '[email protected]',
+ definition: { kind: NodeKind.HogQLQuery, query: 'SELECT 42 AS revenue' },
+})!.config
+
+const meta: Meta<typeof BIMetricSnapshotContext> = {
+ title: 'Products/Business intelligence/Metric snapshot context',
+ component: BIMetricSnapshotContext,
+ args: { config },
+}
+export default meta
+type Story = StoryObj<typeof meta>
+export const Approved: Story = {}
+export const Proposed: Story = {
+ args: { config: { ...config, catalogMetricContext: { ...config.catalogMetricContext!, status: 'proposed' } } },
+}
+export const Drifted: Story = {
+ args: { config: { ...config, catalogMetricContext: { ...config.catalogMetricContext!, isDrifted: true } } },
+}
+export const Legacy: Story = { args: { config: { ...config, catalogMetricContext: undefined } } }
diff --git a/products/business_intelligence/frontend/BIMetricSnapshotContext.test.tsx b/products/business_intelligence/frontend/BIMetricSnapshotContext.test.tsx
new file mode 100644
index 000000000000..7f2275ab075a
--- /dev/null
+++ b/products/business_intelligence/frontend/BIMetricSnapshotContext.test.tsx
@@ -0,0 +1,40 @@
+import '@testing-library/jest-dom'
+
+import { cleanup, render, screen } from '@testing-library/react'
+
+import { NodeKind } from '~/queries/schema/schema-general'
+import { initKeaTests } from '~/test/init'
+
+import { catalogMetricWorksheet } from './biCatalog'
+import { BIMetricSnapshotContext } from './BIMetricSnapshotContext'
+
+afterEach(cleanup)
+
+it.each([
+ ['approved', false, 'Approved'],
+ ['proposed', false, 'Proposed'],
+ ['approved', true, 'Drifted'],
+] as const)('labels %s, drifted=%s as unverified catalog context', (status, is_drifted, label) => {
+ initKeaTests()
+ const config = catalogMetricWorksheet({
+ id: 'example-metric',
+ name: 'revenue',
+ status,
+ is_drifted,
+ unit: 'usd',
+ owner: '[email protected]',
+ definition: { kind: NodeKind.HogQLQuery, query: 'SELECT 42' },
+ })!.config
+ const view = render(<BIMetricSnapshotContext config={config} />)
+ expect(screen.getByText('Catalog status when copied (unverified):')).toBeInTheDocument()
+ expect(screen.getByText(label)).toBeInTheDocument()
+ expect(screen.getByText('Unit: usd')).toBeInTheDocument()
+ expect(screen.getByText('Owner: [email protected]')).toBeInTheDocument()
+ expect(
+ screen.getByText('These saved details are unverified. Check the current catalog entry before using this copy.')
+ ).toBeInTheDocument()
+ expect(view.container.querySelector('.LemonTag--success')).not.toBeInTheDocument()
+ view.rerender(<BIMetricSnapshotContext config={{ ...config, catalogMetricContext: undefined }} />)
+ expect(screen.queryByText('Approved')).not.toBeInTheDocument()
+ expect(screen.getByText('Catalog status was not recorded for this copy.')).toBeInTheDocument()
+})
diff --git a/products/business_intelligence/frontend/BIMetricSnapshotContext.tsx b/products/business_intelligence/frontend/BIMetricSnapshotContext.tsx
new file mode 100644
index 000000000000..55f7eddd32ab
--- /dev/null
+++ b/products/business_intelligence/frontend/BIMetricSnapshotContext.tsx
@@ -0,0 +1,45 @@
+import { LemonBanner, LemonTag, Link } from '@posthog/lemon-ui'
+
+import { urls } from 'scenes/urls'
+
+import { BIConfig } from '~/queries/schema/schema-business-intelligence'
+
+import { metricParameterDrafts } from './biMetricParametersLogic'
+
+export function BIMetricSnapshotContext({ config }: { config: BIConfig }): JSX.Element {
+ const context = config.catalogMetricContext
+ const approved = context?.status === 'approved' && !context.isDrifted
+ return (
+ <LemonBanner type={context && !approved ? 'warning' : 'info'}>
+ <div className="flex min-w-0 flex-col gap-2">
+ <div>
+ This is a SQL copy.{' '}
+ {metricParameterDrafts(config.querySnapshot).length
+ ? 'Edit its parameters below, or use View SQL to change the query.'
+ : 'Use View SQL to edit its dates or grouping in the SQL editor.'}{' '}
+ Catalog changes won't update this copy.
+ </div>
+ {context ? (
+ <div className="flex flex-wrap items-center gap-2 break-words">
+ <span>Catalog status when copied (unverified):</span>
+ <LemonTag type={approved ? 'default' : 'warning'}>
+ {context.isDrifted ? 'Drifted' : context.status === 'approved' ? 'Approved' : 'Proposed'}
+ </LemonTag>
+ {context.unit && <span>Unit: {context.unit}</span>}
+ {context.owner && <span className="break-all">Owner: {context.owner}</span>}
+ </div>
+ ) : (
+ <span>Catalog status was not recorded for this copy.</span>
+ )}
+ {context && (
+ <span>
+ These saved details are unverified. Check the current catalog entry before using this copy.
+ </span>
+ )}
+ {config.catalogMetric && (
+ <Link to={urls.dataCatalogMetric(config.catalogMetric)}>View current catalog entry</Link>
+ )}
+ </div>
+ </LemonBanner>
+ )
+}
diff --git a/products/business_intelligence/frontend/biCatalog.test.ts b/products/business_intelligence/frontend/biCatalog.test.ts
index f422e25587ea..706f7a14dbca 100644
--- a/products/business_intelligence/frontend/biCatalog.test.ts
+++ b/products/business_intelligence/frontend/biCatalog.test.ts
@@ -12,10 +12,33 @@ it('keeps catalog SQL and bound values unchanged when a worksheet is saved or it
query: 'SELECT count(*) FROM events WHERE timestamp >= {start}',
values: { start: '2026-01-01' },
}
- const node = catalogMetricWorksheet({ name: 'revenue', definition: source })!
+ const node = catalogMetricWorksheet({
+ name: 'revenue',
+ definition: source,
+ id: 'metric-revenue',
+ status: 'approved',
+ is_drifted: true,
+ unit: 'usd',
+ owner: '[email protected]',
+ updated_at: '2026-01-01T00:00:00Z',
+ })!
const parsed = parseBIEditorState(BIEditorView.BI, JSON.stringify(node.config))!.config
expect(buildBIQuery({ ...parsed, chartType: ChartDisplayType.BoldNumber })?.node.source).toEqual(source)
expect(parsed.catalogMetric).toBe('revenue')
+ expect(parsed.catalogMetricContext).toEqual({
+ id: 'metric-revenue',
+ status: 'approved',
+ isDrifted: true,
+ unit: 'usd',
+ owner: '[email protected]',
+ updatedAt: '2026-01-01T00:00:00Z',
+ })
+ expect(
+ parseBIEditorState(BIEditorView.BI, {
+ ...parsed,
+ catalogMetricContext: { ...parsed.catalogMetricContext, isDrifted: 'false' },
+ })
+ ).toBeNull()
expect(
parseBIEditorState(
BIEditorView.BI,
@@ -48,6 +71,59 @@ it('attaches draft and metric content as untrusted data and omits oversized draf
).toBe(true)
})
+it('restores catalog-copy drafts when nullable metadata was omitted by the API serializer', () => {
+ const config = {
+ ...DEFAULT_BI_CONFIG,
+ querySnapshot: { kind: NodeKind.HogQLQuery, query: 'SELECT 43 AS edited_revenue' },
+ catalogMetric: 'revenue',
+ catalogMetricContext: { id: 'metric-revenue', status: 'approved', isDrifted: false, unit: 'usd' },
+ }
+ const parsed = parseBIEditorState(BIEditorView.BI, JSON.stringify(config))
+ expect(parsed?.config.querySnapshot).toEqual(config.querySnapshot)
+ expect(parsed?.config.catalogMetricContext).toEqual({
+ ...config.catalogMetricContext,
+ owner: null,
+ updatedAt: null,
+ })
+ for (const field of ['owner', 'updatedAt']) {
+ expect(
+ parseBIEditorState(BIEditorView.BI, {
+ ...config,
+ catalogMetricContext: { ...config.catalogMetricContext, [field]: 42 },
+ })
+ ).toBeNull()
+ }
+})
+
+it.each(['approved', 'proposed', 'unknown', '', null])('validates copied catalog status %p', (status) => {
+ const metric = {
+ name: 'revenue',
+ definition: { kind: NodeKind.HogQLQuery, query: 'SELECT 42' },
+ id: 'metric-revenue',
+ status: status ?? undefined,
+ is_drifted: false,
+ }
+ const node = catalogMetricWorksheet(metric)!
+ const supported = status === 'approved' || status === 'proposed'
+ expect(node.config.catalogMetricContext?.status).toBe(supported ? status : undefined)
+ const parsed = parseBIEditorState(BIEditorView.BI, {
+ ...node.config,
+ catalogMetricContext: {
+ id: metric.id,
+ status,
+ isDrifted: false,
+ unit: '',
+ owner: null,
+ updatedAt: null,
+ },
+ })
+ if (supported) {
+ expect(parsed?.config.catalogMetricContext?.status).toBe(status)
+ } else {
+ expect(parsed).toBeNull()
+ }
+})
+
it('only proposes the successfully executed current query, retaining resolved dates and its row cap', () => {
const node = catalogMetricWorksheet({
name: 'revenue',
diff --git a/products/business_intelligence/frontend/biCatalog.ts b/products/business_intelligence/frontend/biCatalog.ts
index b227d934c3ec..7ddacbe0c961 100644
--- a/products/business_intelligence/frontend/biCatalog.ts
+++ b/products/business_intelligence/frontend/biCatalog.ts
@@ -10,7 +10,8 @@ import { getBIComparisonGroupLimit } from './biComparisonLimit'
import { DEFAULT_BI_CONFIG } from './biEditorTypes'
export function catalogMetricWorksheet(
- metric: Pick<DataCatalogMetricApi, 'name' | 'definition'>
+ metric: Pick<DataCatalogMetricApi, 'name' | 'definition'> &
+ Partial<Pick<DataCatalogMetricApi, 'id' | 'status' | 'is_drifted' | 'unit' | 'owner' | 'updated_at'>>
): BIVisualizationNode | null {
const definition = metric.definition
if (definition?.kind !== NodeKind.HogQLQuery || typeof definition.query !== 'string') {
@@ -30,6 +31,20 @@ export function catalogMetricWorksheet(
chartType: ChartDisplayType.ActionsTable,
querySnapshot: source,
catalogMetric: metric.name,
+ ...(metric.id &&
+ (metric.status === 'approved' || metric.status === 'proposed') &&
+ typeof metric.is_drifted === 'boolean'
+ ? {
+ catalogMetricContext: {
+ id: metric.id,
+ status: metric.status,
+ isDrifted: metric.is_drifted,
+ unit: metric.unit ?? '',
+ owner: metric.owner ?? null,
+ updatedAt: metric.updated_at ?? null,
+ },
+ }
+ : {}),
},
}
}
diff --git a/products/business_intelligence/frontend/biEditorLogic.ts b/products/business_intelligence/frontend/biEditorLogic.ts
index 432df45295d3..d6873b4bfd0a 100644
--- a/products/business_intelligence/frontend/biEditorLogic.ts
+++ b/products/business_intelligence/frontend/biEditorLogic.ts
@@ -119,6 +119,7 @@ function setDataSourceInConfig(config: BIConfig, source: BIDataSource): BIConfig
colorBy: undefined,
querySnapshot: undefined,
catalogMetric: undefined,
+ catalogMetricContext: undefined,
comparisonPeriod: undefined,
rows: [],
columns: [],
diff --git a/products/business_intelligence/frontend/biEditorTypes.ts b/products/business_intelligence/frontend/biEditorTypes.ts
index f95ae8ef891a..f1fdbe700f9e 100644
--- a/products/business_intelligence/frontend/biEditorTypes.ts
+++ b/products/business_intelligence/frontend/biEditorTypes.ts
@@ -705,6 +705,20 @@ export function parseBIEditorState(editorViewValue: unknown, configValue: unknow
if (!isBIAnalysisConfig(candidate)) {
return null
}
+ const metricContext = candidate.catalogMetricContext
+ if (
+ metricContext != null &&
+ (!candidate.querySnapshot ||
+ !candidate.catalogMetric ||
+ typeof metricContext.id !== 'string' ||
+ (metricContext.status !== 'approved' && metricContext.status !== 'proposed') ||
+ typeof metricContext.isDrifted !== 'boolean' ||
+ typeof metricContext.unit !== 'string' ||
+ (metricContext.owner != null && typeof metricContext.owner !== 'string') ||
+ (metricContext.updatedAt != null && typeof metricContext.updatedAt !== 'string'))
+ ) {
+ return null
+ }
if (
candidate.compareFilter !== undefined &&
(!candidate.compareFilter ||
@@ -850,6 +864,15 @@ export function parseBIEditorState(editorViewValue: unknown, configValue: unknow
...(candidate.colorBy === null || typeof candidate.colorBy === 'string' ? { colorBy: candidate.colorBy } : {}),
...(candidate.querySnapshot ? { querySnapshot: candidate.querySnapshot } : {}),
...(candidate.catalogMetric ? { catalogMetric: candidate.catalogMetric } : {}),
+ ...(metricContext
+ ? {
+ catalogMetricContext: {
+ ...metricContext,
+ owner: metricContext.owner ?? null,
+ updatedAt: metricContext.updatedAt ?? null,
+ },
+ }
+ : {}),
...(candidate.localFields ? { localFields: candidate.localFields } : {}),
...(candidate.hierarchies ? { hierarchies: candidate.hierarchies } : {}),
...(candidate.memberAliases ? { memberAliases: candidate.memberAliases } : {}),
diff --git a/products/dashboards/frontend/generated/api.schemas.ts b/products/dashboards/frontend/generated/api.schemas.ts
index d13c800fc89f..e8b693471eee 100644
--- a/products/dashboards/frontend/generated/api.schemas.ts
+++ b/products/dashboards/frontend/generated/api.schemas.ts
@@ -9337,6 +9337,22 @@ export interface DataVisualizationNodeApi {
version?: number | null
}
+export type BICatalogMetricStatusApi = (typeof BICatalogMetricStatusApi)[keyof typeof BICatalogMetricStatusApi]
+
+export const BICatalogMetricStatusApi = {
+ Approved: 'approved',
+ Proposed: 'proposed',
+} as const
+
+export interface CatalogMetricContextApi {
+ id: string
+ isDrifted: boolean
+ owner?: string | null
+ status: BICatalogMetricStatusApi
+ unit: string
+ updatedAt?: string | null
+}
+
export type BIDateBucketApi = (typeof BIDateBucketApi)[keyof typeof BIDateBucketApi]
export const BIDateBucketApi = {
@@ -9633,6 +9649,8 @@ export interface BIValueApi {
export interface BIConfigApi {
/** Catalog provenance only: the snapshot does not track subsequent definition edits. */
catalogMetric?: string | null
+ /** Catalog metadata at copy time, not a live approval of the worksheet. */
+ catalogMetricContext?: CatalogMetricContextApi | null
chartType: ChartDisplayTypeApi
colorBy?: string | null
columns: BIFieldApi[]
diff --git a/products/desktop/packages/api-client/src/generated.ts b/products/desktop/packages/api-client/src/generated.ts
index e20c6beafd1a..a329916533d6 100644
--- a/products/desktop/packages/api-client/src/generated.ts
+++ b/products/desktop/packages/api-client/src/generated.ts
@@ -4537,6 +4537,7 @@ export namespace Schemas {
| "minimum"
| "maximum"
| "custom";
+ export type BICatalogMetricStatus = "approved" | "proposed";
export type BICategoryGroup = { name: string; values: Array<string> };
export type Operator1 = "AND" | "OR";
export type BIConditionGroup = {
@@ -4544,6 +4545,14 @@ export namespace Schemas {
groups: Array<BIConditionGroup>;
operator: Operator1;
};
+ export type CatalogMetricContext = {
+ id: string;
+ isDrifted: boolean;
+ owner?: (string | null) | undefined;
+ status: BICatalogMetricStatus;
+ unit: string;
+ updatedAt?: (string | null) | undefined;
+ };
export type BIDateBucket =
| "minute"
| "hour"
@@ -4735,6 +4744,7 @@ export namespace Schemas {
};
export type BIConfig = {
catalogMetric?: (string | null) | undefined;
+ catalogMetricContext?: (CatalogMetricContext | null) | undefined;
chartType: ChartDisplayType;
colorBy?: (string | null) | undefined;
columns: Array<BIField>;
diff --git a/products/product_analytics/frontend/generated/api.schemas.ts b/products/product_analytics/frontend/generated/api.schemas.ts
index 4aeccf63cebf..af696328e166 100644
--- a/products/product_analytics/frontend/generated/api.schemas.ts
+++ b/products/product_analytics/frontend/generated/api.schemas.ts
@@ -8164,6 +8164,22 @@ export interface DataVisualizationNodeApi {
version?: number | null
}
+export type BICatalogMetricStatusApi = (typeof BICatalogMetricStatusApi)[keyof typeof BICatalogMetricStatusApi]
+
+export const BICatalogMetricStatusApi = {
+ Approved: 'approved',
+ Proposed: 'proposed',
+} as const
+
+export interface CatalogMetricContextApi {
+ id: string
+ isDrifted: boolean
+ owner?: string | null
+ status: BICatalogMetricStatusApi
+ unit: string
+ updatedAt?: string | null
+}
+
export type BIDateBucketApi = (typeof BIDateBucketApi)[keyof typeof BIDateBucketApi]
export const BIDateBucketApi = {
@@ -8460,6 +8476,8 @@ export interface BIValueApi {
export interface BIConfigApi {
/** Catalog provenance only: the snapshot does not track subsequent definition edits. */
catalogMetric?: string | null
+ /** Catalog metadata at copy time, not a live approval of the worksheet. */
+ catalogMetricContext?: CatalogMetricContextApi | null
chartType: ChartDisplayTypeApi
colorBy?: string | null
columns: BIFieldApi[]
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index 5405e014d276..4f4d379b30c8 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -10786,6 +10786,23 @@ export namespace Schemas {
version?: number | null;
}
+ export type BICatalogMetricStatus = typeof BICatalogMetricStatus[keyof typeof BICatalogMetricStatus];
+
+
+ export const BICatalogMetricStatus = {
+ Approved: 'approved',
+ Proposed: 'proposed',
+ } as const;
+
+ export interface CatalogMetricContext {
+ id: string;
+ isDrifted: boolean;
+ owner?: string | null;
+ status: BICatalogMetricStatus;
+ unit: string;
+ updatedAt?: string | null;
+ }
+
export type BIDateBucket = typeof BIDateBucket[keyof typeof BIDateBucket];
@@ -11095,6 +11112,8 @@ export namespace Schemas {
export interface BIConfig {
/** Catalog provenance only: the snapshot does not track subsequent definition edits. */
catalogMetric?: string | null;
+ /** Catalog metadata at copy time, not a live approval of the worksheet. */
+ catalogMetricContext?: CatalogMetricContext | null;
chartType: ChartDisplayType;
colorBy?: string | null;
columns: BIField[];