: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(postgres): stop retrying a proxy account restriction we don't recognise (#102874)
Tom Owersbb2c31890b9c
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/source.pyindex 51fd45f4f841..df86518033c6 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/source.py@@ -888,10 +888,26 @@ class PostgresSource(SQLSource[PostgresSourceConfig], SSHTunnelMixin, ValidateDa# contact the provider), so every retry re-hits the same refusal. Match the stable# camelCase reason code, which carries no host or account detail."planLimitReached": (- "Your database provider has restricted the account because a plan limit was reached "- '("planLimitReached"), so PostHog can\'t connect. This usually comes from a database '- "proxy such as Prisma. Upgrade the plan or contact your provider to lift the "- "restriction, then re-enable the sync."+ "Your database provider has restricted the account because a plan limit was reached, "+ "so PostHog can't connect. This usually comes from a database proxy such as Prisma. "+ "Upgrade the plan or contact your provider to lift the restriction, then re-enable "+ "the sync."+ ),+ # The billing sibling of the code above, from the same restriction sentence: the proxy+ # refuses the connection because an invoice is unpaid. Only the customer's billing+ # settles it, so every retry re-hits the refusal. Match the stable camelCase reason code.+ "unpaidPlanInvoice": (+ "Your database provider has restricted the account over an unpaid invoice, so PostHog "+ "can't connect. Settle it with your provider, then re-enable the sync."+ ),+ # Any other restriction reason from that same sentence. The reason codes are the+ # provider's own and open-ended, so without this catch-all the next one burns a job on+ # every schedule and stores the raw refusal — which libpq prefixes with the customer's+ # host and port. Placed after the two specific codes, whose guidance is more actionable,+ # because finalization takes the first matching entry.+ "Your account has restrictions": (+ "Your database provider has restricted the account, so PostHog can't connect. Contact "+ "your provider to lift the restriction, then re-enable the sync."),# The provider has put the cluster into read-only mode, so it rejects our read (the# server-side cursor runs its SELECT inside a read/write transaction). PlanetScale'sdiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/test_postgres.py b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/test_postgres.pyindex cfdb58653a61..131ebe963137 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/test_postgres.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/test_postgres.py@@ -536,18 +536,42 @@ class TestPostgresSourceNonRetryableErrors:assert "re-enable the sync" in matches[0].lower()assert "db.example.com" not in matches[0]- def test_plan_limit_restriction_surfaces_actionable_message(self, source):- # A proxy plan-limit refusal must stop retrying and explain how to lift the restriction,- # rather than storing the raw provider text. Mirror the finalizer's first-match selection.- error_msg = "Your account has restrictions: planLimitReached. Please contact your provider to resolve account restrictions."+ @pytest.mark.parametrize(+ ("error_msg", "reason_code", "expected_word"),+ [+ (+ "Your account has restrictions: planLimitReached. Please contact your provider to resolve account restrictions.",+ "planLimitReached",+ "plan",+ ),+ # The billing reason code, carrying the libpq connect prefix the proxy's refusal arrives+ # with. Host and port are invented, not real values.+ (+ 'connection failed: connection to server at "203.0.113.7", port 5432 failed: Failed to identify your database: Your account has restrictions: unpaidPlanInvoice. Please contact your provider to resolve account restrictions.',+ "unpaidPlanInvoice",+ "invoice",+ ),+ # A reason code we don't recognise yet must still stop retrying and say who to contact.+ ("Your account has restrictions: someFutureReason.", "someFutureReason", "restricted"),+ ],+ )+ def test_account_restriction_surfaces_actionable_message(self, source, error_msg, reason_code, expected_word):+ # A proxy account-restriction refusal must stop retrying and explain how to lift the+ # restriction, rather than storing the raw provider text (which libpq prefixes with the+ # customer's host and port). Mirror the finalizer's first-match selection so a reorder that+ # shadows a specific reason code with the catch-all is caught.matches = [friendlyfor pattern, friendly in source.get_non_retryable_errors().items()if error_message_matches(error_msg, [pattern])]- assert matches, "plan-limit restriction must be classified non-retryable"- assert matches[0] is not None, "plan-limit restriction must surface an actionable message, not raw driver text"- assert "plan" in matches[0].lower()+ assert matches, f"an account restriction must be classified non-retryable: {error_msg}"+ assert matches[0] is not None, (+ "an account restriction must surface an actionable message, not raw provider text"+ )+ assert expected_word in matches[0].lower()+ assert reason_code not in matches[0], "the provider's reason code must stay out of the customer-facing message"+ assert "203.0.113.7" not in matches[0]@pytest.mark.parametrize("error_msg",