: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(supabase): explain expired realtime.messages partitions in sync error (#83109)
Tom Owersfac56729c869
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/supabase/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/supabase/source.pyindex 75ed6c27e107..60ed10a5fff0 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/supabase/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/supabase/source.py@@ -70,6 +70,21 @@ _SUPABASE_DIRECT_HOST_IPV4_HINT = ("(aws-0-<region>.pooler.supabase.com) with username postgres.<project-ref>.")+# Supabase Realtime stores messages in daily partitions of its internal `realtime.messages` table+# named `realtime.messages_YYYY_MM_DD`, and its retention job drops the old partitions. A sync that+# targets one of these dated partitions fails with `relation "realtime.messages_..." does not exist`+# once that day is dropped. Match the stable partition-name prefix (never the volatile date). The+# inherited generic `"does not exist"` already classifies this non-retryable; this entry only adds an+# actionable message, so it must precede the generic key in `get_non_retryable_errors` (first match+# wins) with a non-None value.+_SUPABASE_REALTIME_PARTITION_ERROR = "realtime.messages_"+_SUPABASE_REALTIME_PARTITION_MESSAGE = (+ "Supabase creates a new realtime.messages partition each day and drops old ones automatically, "+ "so the dated partition this sync read no longer exists. These partitions are temporary and "+ "aren't meant to be synced. Remove this table from the source's selected tables, then re-enable "+ "the sync."+)+@SourceRegistry.registerclass SupabaseSource(PostgresSource):@@ -80,6 +95,12 @@ class SupabaseSource(PostgresSource):def source_type(self) -> ExternalDataSourceType:return ExternalDataSourceType.SUPABASE+ def get_non_retryable_errors(self) -> dict[str, str | None]:+ return {+ _SUPABASE_REALTIME_PARTITION_ERROR: _SUPABASE_REALTIME_PARTITION_MESSAGE,+ **super().get_non_retryable_errors(),+ }+@staticmethoddef _adjust_field(field: _SourceField) -> _SourceField:if isinstance(field, SourceFieldInputConfig) and field.name == "host":diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/supabase/test_supabase_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/supabase/test_supabase_source.pyindex 76e6fe299948..a2edd33c2231 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/supabase/test_supabase_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/supabase/test_supabase_source.py@@ -3,6 +3,7 @@ from unittest import mockfrom posthog.schema import ReleaseStatus, SourceFieldInputConfig+from products.warehouse_sources.backend.temporal.data_imports.sources.common.base import error_message_matchesfrom products.warehouse_sources.backend.temporal.data_imports.sources.postgres.source import (_HOST_UNREACHABLE_ERROR,PostgresSource,@@ -144,3 +145,32 @@ def test_non_direct_host_failure_uses_postgres_error(host):assert success is Falseassert error == "postgres error"+++def _resolve_friendly_error(source: SupabaseSource, raw_error: str) -> str | None:+ # Mirrors external_data_job.update_external_data_job_model: first matching key wins.+ for pattern, friendly in source.get_non_retryable_errors().items():+ if error_message_matches(raw_error, [pattern]):+ return friendly+ return None+++ "raw_error,expect_message",+ [+ # Retention dropped the dated realtime.messages partition — actionable message, not the+ # inherited generic "does not exist" (which resolves to None / the raw driver string).+ ('relation "realtime.messages_2020_01_01" does not exist', True),+ # A regular missing table must still fall through to the generic (None) mapping, so the+ # realtime key stays specific and doesn't swallow every "does not exist".+ ('relation "public.orders" does not exist', False),+ ],+)+def test_expired_realtime_partition_gets_actionable_message(raw_error, expect_message):+ friendly = _resolve_friendly_error(SupabaseSource(), raw_error)++ if expect_message:+ assert friendly is not None+ assert "realtime.messages" in friendly+ else:+ assert friendly is None