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-quality): name the check on each row of a run (#93737)

Thiago Salvatore52dd76d6ae97
diff --git a/products/data_quality/backend/presentation/serializers.py b/products/data_quality/backend/presentation/serializers.py
index b46ef5e75c90..766f48a22a09 100644
--- a/products/data_quality/backend/presentation/serializers.py
+++ b/products/data_quality/backend/presentation/serializers.py
@@ -261,12 +261,27 @@ class DataQualityCheckRunSerializer(serializers.ModelSerializer):
allow_null=True,
help_text="Severity this run was judged at. Null for runs recorded before snapshots existed.",
)
+ check_name = serializers.SerializerMethodField(
+ help_text="Name the check carries now, so a run can be told from the others in its suite. "
+ "Null when the check is unnamed, has been hard deleted, or is out of your reach today -- "
+ "describe the run by check_type and column_name instead."
+ )
+
+ @extend_schema_field(serializers.CharField(allow_null=True))
+ def get_check_name(self, obj: DataQualityCheckRun) -> str | None:
+ # A surface that serves runs from several checks passes the ones it may not name; a surface
+ # that already authorized the single check it serves passes nothing and names it.
+ check = obj.quality_check
+ if not check or check.id in self.context.get("unnamable_check_ids", frozenset()):
+ return None
+ return check.name or None
class Meta:
model = DataQualityCheckRun
fields = [
"id",
"quality_check",
+ "check_name",
"suite_run",
"subject_type",
"subject_uuid",
diff --git a/products/data_quality/backend/presentation/views.py b/products/data_quality/backend/presentation/views.py
index 3ef4dfa4a135..1cb6601e8291 100644
--- a/products/data_quality/backend/presentation/views.py
+++ b/products/data_quality/backend/presentation/views.py
@@ -9,7 +9,7 @@ a suite-run handle to poll.
import json
from collections import defaultdict
-from collections.abc import Callable
+from collections.abc import Callable, Sequence
from typing import ClassVar, cast
from uuid import UUID
@@ -124,6 +124,15 @@ class _QualityGatedViewSet(TeamAndOrgViewSetMixin):
visible = api.visible_checks(self.team_id, checks, self._denial_context())
return {check.id for check in checks} - {check.id for check in visible}
+ def _unnamable_check_ids(self, runs: Sequence[DataQualityCheckRun]) -> set[UUID]:
+ # A run is judged by the identities it recorded, but the name on its check is present tense.
+ # Withhold the name of a check that is out of reach today, even where the run it left behind
+ # stays readable on its own terms.
+ if not self._can_be_object_denied():
+ return set()
+ checks = {run.quality_check.id: run.quality_check for run in runs if run.quality_check}
+ return self._hidden_check_ids(list(checks.values()))
+
def _readable_runs(self, runs: QuerySet[DataQualityCheckRun]) -> QuerySet[DataQualityCheckRun]:
# Excluded in SQL rather than per page, so a run that read a subject out of reach is gone
# before the window that bounds what is served.
@@ -466,10 +475,15 @@ class _BaseSuiteRunViewSet(
@action(methods=["GET"], detail=True, url_path="check_runs", pagination_class=None)
def check_runs(self, request: Request, **kwargs) -> Response:
suite_run = self.get_object()
- runs = self._readable_runs(
- DataQualityCheckRun.objects.for_team(self.team_id).filter(suite_run=suite_run)
- ).select_related("quality_check")
- return Response(DataQualityCheckRunSerializer(list(runs.order_by("-created_at")), many=True).data)
+ runs = list(
+ self._readable_runs(DataQualityCheckRun.objects.for_team(self.team_id).filter(suite_run=suite_run))
+ .select_related("quality_check")
+ .order_by("-created_at")
+ )
+ serializer = DataQualityCheckRunSerializer(
+ runs, many=True, context={"unnamable_check_ids": self._unnamable_check_ids(runs)}
+ )
+ return Response(serializer.data)
def _parent_id_parameter(name: str, description: str) -> Callable[[type], type]:
diff --git a/products/data_quality/backend/tests/test_api.py b/products/data_quality/backend/tests/test_api.py
index 297168928073..e512357753cd 100644
--- a/products/data_quality/backend/tests/test_api.py
+++ b/products/data_quality/backend/tests/test_api.py
@@ -520,6 +520,29 @@ class TestDataQualityCheckAPI(APIBaseTest):
check_runs = self.client.get(f"{base}/{mine.id}/check_runs/")
assert [row["subject_name"] for row in check_runs.json()] == ["orders"]
+ def test_check_runs_name_the_check_each_row_ran(self) -> None:
+ named = self._create_check(name="orders_customer_id_not_null")
+ suite = DataQualitySuiteRun.objects.for_team(self.team.id).create(
+ team=self.team, trigger="manual", subject_type=SubjectType.VIEW, subject_uuid=self.view.id
+ )
+ for quality_check in (named, None):
+ DataQualityCheckRun.objects.for_team(self.team.id).create(
+ team=self.team,
+ suite_run=suite,
+ quality_check=quality_check,
+ subject_type=SubjectType.VIEW,
+ subject_uuid=self.view.id,
+ subject_name="orders",
+ check_type=CheckType.NOT_NULL,
+ check_fingerprint=uuid4().hex,
+ status=CheckRunStatus.PASSED,
+ )
+
+ response = self.client.get(f"{self._suite_runs_url()}/{suite.id}/check_runs/")
+
+ assert response.status_code == status.HTTP_200_OK
+ assert {row["check_name"] for row in response.json()} == {"orders_customer_id_not_null", None}
+
def test_listing_a_subjects_checks_leaves_out_the_ones_reading_a_denied_subject(self) -> None:
# The parent gate cleared "customers", but a check under it names the denied "orders" in its
# config, which the routes that address one check already refuse to serve.
@@ -989,6 +1012,49 @@ class TestDataQualityCheckAPI(APIBaseTest):
assert response.status_code == status.HTTP_200_OK
assert [row["check_type"] for row in response.json()] == [CheckType.CUSTOM_SQL]
+ def test_a_readable_run_does_not_name_a_check_the_member_may_no_longer_see(self) -> None:
+ # The run pinned an allowed view, so its history stays readable -- but the name on its check
+ # is present tense, and the check now reads the denied "orders". Serving the name hands over
+ # what a teammate called a check this member is no longer shown.
+ allowed = self._make_view("customers")
+ check = DataQualityCheck.objects.for_team(self.team.id).create(
+ team=self.team,
+ name="nightly_customers_audit",
+ subject_type=SubjectType.VIEW,
+ saved_query_id=allowed.id,
+ subject_name="customers",
+ check_type=CheckType.CUSTOM_SQL,
+ config={"query": "SELECT 1 FROM customers"},
+ fingerprint=uuid4().hex,
+ )
+ suite = DataQualitySuiteRun.objects.for_team(self.team.id).create(
+ team=self.team, trigger="manual", subject_type=SubjectType.VIEW, subject_uuid=allowed.id
+ )
+ api.record_check_run(
+ self.team.id,
+ suite_run=suite,
+ quality_check=check,
+ subject_type=SubjectType.VIEW,
+ subject_uuid=allowed.id,
+ subject_name="customers",
+ check_type=CheckType.CUSTOM_SQL,
+ check_config={"query": "SELECT 1 FROM customers"},
+ referenced_subjects=self._pinned(allowed),
+ check_fingerprint=check.fingerprint,
+ status=CheckRunStatus.FAILED,
+ failed_row_count=3,
+ )
+ DataQualityCheck.objects.for_team(self.team.id).filter(id=check.id).update(
+ config={"query": "SELECT 1 FROM orders"}
+ )
+ self._deny_the_view()
+
+ response = self.client.get(f"{self._suite_runs_url(allowed.id)}/{suite.id}/check_runs/")
+
+ assert response.status_code == status.HTTP_200_OK
+ assert [row["check_type"] for row in response.json()] == [CheckType.CUSTOM_SQL]
+ assert [row["check_name"] for row in response.json()] == [None]
+
def test_a_deleted_declared_subject_withholds_its_history_from_a_restricted_member(self) -> None:
# Deleting a subject takes its denial with it, so nothing left can show the caller was
# allowed it. The run, its suite, and the check all fall out until retention deletes them.
diff --git a/products/data_quality/frontend/CheckRunsTable.tsx b/products/data_quality/frontend/CheckRunsTable.tsx
index 68f3ad068334..e8aadb2b38f1 100644
--- a/products/data_quality/frontend/CheckRunsTable.tsx
+++ b/products/data_quality/frontend/CheckRunsTable.tsx
@@ -1,68 +1,77 @@
import { LemonTable, LemonTag, Tooltip } from '@posthog/lemon-ui'
import { TZLabel } from 'lib/components/TZLabel'
+import { LemonTableColumn } from 'lib/lemon-ui/LemonTable'
import { humanFriendlyDuration } from 'lib/utils/durations'
import { humanFriendlyNumber } from 'lib/utils/numbers'
-import { CHECK_STATUS_TAG_TYPES } from './checksConstants'
+import { CHECK_STATUS_TAG_TYPES, byStatusAttention, checkRunDisplayName } from './checksConstants'
import type { DataQualityCheckRunApi } from './generated/api.schemas'
+type CheckRunColumn = LemonTableColumn<DataQualityCheckRunApi, keyof DataQualityCheckRunApi | undefined>
+
+const CHECK_COLUMN: CheckRunColumn = {
+ title: 'Check',
+ key: 'check',
+ render: (_, run) => <span className="font-semibold">{checkRunDisplayName(run)}</span>,
+}
+
+const OUTCOME_COLUMNS: CheckRunColumn[] = [
+ {
+ title: 'Status',
+ key: 'status',
+ render: (_, run) => <LemonTag type={CHECK_STATUS_TAG_TYPES[run.status] ?? 'default'}>{run.status}</LemonTag>,
+ },
+ {
+ title: 'Started',
+ key: 'started_at',
+ render: (_, run) => (run.started_at ? <TZLabel time={run.started_at} /> : '-'),
+ },
+ {
+ title: 'Duration',
+ key: 'duration_ms',
+ render: (_, run) =>
+ run.duration_ms === null ? '-' : humanFriendlyDuration(run.duration_ms / 1000, { maxUnits: 2 }),
+ },
+ {
+ title: 'Observed value',
+ key: 'observed_value',
+ render: (_, run) => (run.observed_value === null ? '-' : humanFriendlyNumber(run.observed_value)),
+ },
+ {
+ title: 'Failed rows',
+ key: 'failed_row_count',
+ render: (_, run) => (run.failed_row_count === null ? '-' : humanFriendlyNumber(run.failed_row_count)),
+ },
+ {
+ title: 'Error',
+ key: 'error',
+ render: (_, run) =>
+ run.error ? (
+ <Tooltip title={run.error}>
+ <span className="text-danger truncate max-w-xs inline-block">{run.error}</span>
+ </Tooltip>
+ ) : (
+ '-'
+ ),
+ },
+]
+
interface CheckRunsTableProps {
runs: DataQualityCheckRunApi[]
loading?: boolean
+ showCheck?: boolean
}
-export function CheckRunsTable({ runs, loading }: CheckRunsTableProps): JSX.Element {
+export function CheckRunsTable({ runs, loading, showCheck }: CheckRunsTableProps): JSX.Element {
return (
<LemonTable
size="small"
- dataSource={runs}
+ dataSource={showCheck ? [...runs].sort(byStatusAttention) : runs}
loading={loading}
nouns={['run', 'runs']}
emptyState="No runs yet"
- columns={[
- {
- title: 'Status',
- key: 'status',
- render: (_, run) => (
- <LemonTag type={CHECK_STATUS_TAG_TYPES[run.status] ?? 'default'}>{run.status}</LemonTag>
- ),
- },
- {
- title: 'Started',
- key: 'started_at',
- render: (_, run) => (run.started_at ? <TZLabel time={run.started_at} /> : '-'),
- },
- {
- title: 'Duration',
- key: 'duration_ms',
- render: (_, run) =>
- run.duration_ms === null ? '-' : humanFriendlyDuration(run.duration_ms / 1000, { maxUnits: 2 }),
- },
- {
- title: 'Observed value',
- key: 'observed_value',
- render: (_, run) => (run.observed_value === null ? '-' : humanFriendlyNumber(run.observed_value)),
- },
- {
- title: 'Failed rows',
- key: 'failed_row_count',
- render: (_, run) =>
- run.failed_row_count === null ? '-' : humanFriendlyNumber(run.failed_row_count),
- },
- {
- title: 'Error',
- key: 'error',
- render: (_, run) =>
- run.error ? (
- <Tooltip title={run.error}>
- <span className="text-danger truncate max-w-xs inline-block">{run.error}</span>
- </Tooltip>
- ) : (
- '-'
- ),
- },
- ]}
+ columns={showCheck ? [CHECK_COLUMN, ...OUTCOME_COLUMNS] : OUTCOME_COLUMNS}
/>
)
}
diff --git a/products/data_quality/frontend/SuiteRunsHistory.tsx b/products/data_quality/frontend/SuiteRunsHistory.tsx
index ce2fb2da56a9..395b33717199 100644
--- a/products/data_quality/frontend/SuiteRunsHistory.tsx
+++ b/products/data_quality/frontend/SuiteRunsHistory.tsx
@@ -36,6 +36,7 @@ export function SuiteRunsHistory(props: DataQualityChecksLogicProps): JSX.Elemen
<CheckRunsTable
runs={suiteRunCheckRunsBySuiteRunId[suiteRun.id] ?? []}
loading={pendingCheckActions.loadingSuiteRunRuns[suiteRun.id]}
+ showCheck
/>
),
}}
diff --git a/products/data_quality/frontend/checksConstants.test.ts b/products/data_quality/frontend/checksConstants.test.ts
index 8beb69fa6e61..b0f1d2723ccd 100644
--- a/products/data_quality/frontend/checksConstants.test.ts
+++ b/products/data_quality/frontend/checksConstants.test.ts
@@ -1,6 +1,7 @@
import { dayjs } from 'lib/dayjs'
-import { failingForLabel } from './checksConstants'
+import { byStatusAttention, checkRunDisplayName, failingForLabel } from './checksConstants'
+import { CheckTypeEnumApi } from './generated/api.schemas'
describe('checksConstants', () => {
const now = dayjs('2026-08-19T12:00:00Z')
@@ -34,4 +35,31 @@ describe('checksConstants', () => {
)
).toEqual(expected)
})
+
+ it.each<[string, string | null, CheckTypeEnumApi, string, string]>([
+ [
+ 'a named check is labelled by its name',
+ 'orders_are_fresh',
+ CheckTypeEnumApi.Freshness,
+ '',
+ 'orders_are_fresh',
+ ],
+ ['an unnamed check describes its assertion', null, CheckTypeEnumApi.NotNull, 'email', 'Not null on email'],
+ ['a check on no column names the type alone', null, CheckTypeEnumApi.RowCount, '', 'Row count'],
+ ])('%s', (_case, checkName, checkType, columnName, expected) => {
+ expect(checkRunDisplayName({ check_name: checkName, check_type: checkType, column_name: columnName })).toEqual(
+ expected
+ )
+ })
+
+ it('sorts the runs that need a person above the ones that do not', () => {
+ const runs = [{ status: 'passed' }, { status: 'skipped' }, { status: 'errored' }, { status: 'failed' }]
+
+ expect([...runs].sort(byStatusAttention).map((run) => run.status)).toEqual([
+ 'failed',
+ 'errored',
+ 'skipped',
+ 'passed',
+ ])
+ })
})
diff --git a/products/data_quality/frontend/checksConstants.ts b/products/data_quality/frontend/checksConstants.ts
index b61d57df4dae..233bf0262769 100644
--- a/products/data_quality/frontend/checksConstants.ts
+++ b/products/data_quality/frontend/checksConstants.ts
@@ -2,7 +2,7 @@ import { Dayjs, dayjs } from 'lib/dayjs'
import { LemonTagType } from 'lib/lemon-ui/LemonTag'
import { CheckTypeEnumApi } from './generated/api.schemas'
-import type { DataQualityCheckApi } from './generated/api.schemas'
+import type { DataQualityCheckApi, DataQualityCheckRunApi } from './generated/api.schemas'
export const CHECK_TYPE_LABELS: Record<string, string> = {
[CheckTypeEnumApi.NotNull]: 'Not null',
@@ -21,6 +21,25 @@ export const CHECK_STATUS_TAG_TYPES: Record<string, LemonTagType> = {
skipped: 'muted',
}
+const CHECK_STATUS_ATTENTION_ORDER: Record<string, number> = {
+ failed: 0,
+ errored: 1,
+ skipped: 2,
+ passed: 3,
+}
+
+const LAST_ATTENTION_RANK = Object.keys(CHECK_STATUS_ATTENTION_ORDER).length
+
+export function byStatusAttention(
+ a: Pick<DataQualityCheckRunApi, 'status'>,
+ b: Pick<DataQualityCheckRunApi, 'status'>
+): number {
+ return (
+ (CHECK_STATUS_ATTENTION_ORDER[a.status] ?? LAST_ATTENTION_RANK) -
+ (CHECK_STATUS_ATTENTION_ORDER[b.status] ?? LAST_ATTENTION_RANK)
+ )
+}
+
export const SUITE_RUN_STATUS_TAG_TYPES: Record<string, LemonTagType> = {
running: 'primary',
completed: 'success',
@@ -78,11 +97,23 @@ export function checkTypeLabel(checkType: string): string {
return CHECK_TYPE_LABELS[checkType] ?? checkType
}
+interface NamedCheck {
+ name?: string | null
+ check_type: string
+ column_name?: string | null
+}
+
/** The check's own name when it has one, otherwise a description of the assertion it makes. */
-export function checkDisplayName(check: Pick<DataQualityCheckApi, 'name' | 'check_type' | 'column_name'>): string {
+export function checkDisplayName(check: NamedCheck): string {
if (check.name) {
return check.name
}
const label = checkTypeLabel(check.check_type)
return check.column_name ? `${label} on ${check.column_name}` : label
}
+
+export function checkRunDisplayName(
+ run: Pick<DataQualityCheckRunApi, 'check_name' | 'check_type' | 'column_name'>
+): string {
+ return checkDisplayName({ name: run.check_name, check_type: run.check_type, column_name: run.column_name })
+}
diff --git a/products/data_quality/frontend/generated/api.schemas.ts b/products/data_quality/frontend/generated/api.schemas.ts
index 59b69a544753..dcbe6df0d0cc 100644
--- a/products/data_quality/frontend/generated/api.schemas.ts
+++ b/products/data_quality/frontend/generated/api.schemas.ts
@@ -327,6 +327,11 @@ export interface DataQualityCheckRunApi {
* @nullable
*/
readonly quality_check: string | null
+ /**
+ * Name the check carries now, so a run can be told from the others in its suite. Null when the check is unnamed, has been hard deleted, or is out of your reach today -- describe the run by check_type and column_name instead.
+ * @nullable
+ */
+ readonly check_name: string | null
readonly suite_run: string
readonly subject_type: SubjectTypeEnumApi
readonly subject_uuid: string
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index 239c59cb9971..829888cfa713 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -21564,6 +21564,11 @@ export namespace Schemas {
* @nullable
*/
readonly quality_check: string | null;
+ /**
+ * Name the check carries now, so a run can be told from the others in its suite. Null when the check is unnamed, has been hard deleted, or is out of your reach today -- describe the run by check_type and column_name instead.
+ * @nullable
+ */
+ readonly check_name: string | null;
readonly suite_run: string;
readonly subject_type: SubjectTypeEnum;
readonly subject_uuid: string;