: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(signals): drop null report ids in inbox ranking labeled-ids query (#78853)
Andrew Maguire19445d0efcb3
diff --git a/products/signals/dags/inbox_ranking/dataset/queries.py b/products/signals/dags/inbox_ranking/dataset/queries.pyindex 5a7903caa00a..0a150ed705ba 100644--- a/products/signals/dags/inbox_ranking/dataset/queries.py+++ b/products/signals/dags/inbox_ranking/dataset/queries.py@@ -74,7 +74,7 @@ def hogql_rows(sql: str, *, team: Team, query_type: str, snapshot_end: datetime.return [tuple(row) for row in response.results or []]-def canonical_report_uuid(report_id: str) -> str | None:+def canonical_report_uuid(report_id: str | None) -> str | None:"""Canonical lowercase-hyphenated form of a client-supplied report id, or None when it cannotbe a report UUID. Canonicalizing (not just validating) matters because a case or hyphenationvariant would otherwise survive as a separate label-only row instead of joining its report."""@@ -82,9 +82,13 @@ def canonical_report_uuid(report_id: str) -> str | None:return str(uuid.UUID(report_id))except ValueError:return None+ except TypeError:+ # uuid.UUID(None) raises TypeError, not ValueError; a missing event property surfaces+ # as a None cell in HogQL results.+ return None-def valid_report_uuids(report_ids: set[str]) -> set[str]:+def valid_report_uuids(report_ids: set[str | None]) -> set[str]:"""Label events are client-supplied; drop ids that cannot be report UUIDs before ORM lookups."""return {canonical for report_id in report_ids if (canonical := canonical_report_uuid(report_id)) is not None}@@ -122,7 +126,10 @@ FROM (WHERE event IN ('pr_created', 'pr_merged', 'pr_closed')AND timestamp >= toDateTime({{labels_epoch}}) AND timestamp < toDateTime({{snapshot_end}}))-WHERE report_id != ''+-- The null guard is load-bearing: an event missing its report id property yields a NULL report_id+-- (most pr_* events are not born from a signal report), and HogQL's null-safe inequality evaluates+-- NULL != '' to true, so the empty-string filter alone would pass a NULL row through.+WHERE report_id IS NOT NULL AND report_id != ''"""# Point-in-time caveat: the source is a ReplacingMergeTree versioned by inserted_at, so mergesdiff --git a/products/signals/dags/inbox_ranking/tests/test_dataset.py b/products/signals/dags/inbox_ranking/tests/test_dataset.pyindex 3baff19cf6f2..b4b0fe23f668 100644--- a/products/signals/dags/inbox_ranking/tests/test_dataset.py+++ b/products/signals/dags/inbox_ranking/tests/test_dataset.py@@ -79,8 +79,10 @@ def test_snapshot_bounds_cover_the_partition_day():def test_valid_report_uuids_canonicalizes_and_drops_junk():# Case/hyphenation variants must collapse onto the canonical id, or a forged variant would- # survive as a separate label-only training row instead of joining its report.- assert valid_report_uuids({UUID_A, UUID_A.upper(), "not-a-uuid", ""}) == {UUID_A}+ # survive as a separate label-only training row instead of joining its report. None reaches+ # here when a label event lacks its report id property (uuid.UUID(None) raises TypeError,+ # which must be swallowed like ValueError, not fail the asset).+ assert valid_report_uuids({UUID_A, UUID_A.upper(), "not-a-uuid", "", None}) == {UUID_A}def test_utc_bound_carries_an_explicit_offset():