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(warehouse): snowflake 403 message covers expired result urls (#95461)

Daniel RC273ec88c11c3
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/snowflake/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/snowflake/source.py
index c60f1d465cd5..92d81af195e3 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/snowflake/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/snowflake/source.py
@@ -324,12 +324,19 @@ class SnowflakeSource(SQLSource[SnowflakeSourceConfig]):
"but view query produces": "A Snowflake view in your source is invalid — the columns it declares no longer match the columns its query returns. Please recreate the view in Snowflake so the two agree, then resync.",
# Snowflake connector error 290403 (ER_HTTP_GENERAL_ERROR + 403): a request to Snowflake
# returned HTTP 403 Forbidden and kept doing so through the connector's own retry budget.
- # The connector treats 403 as retryable and retries within the request timeout, so a
- # ForbiddenError reaching us means the 403 is persistent — an access-denied condition
- # (a network policy/firewall/proxy blocking PostHog, or the role's access to the data
- # being revoked), not a transient blip. Retrying the whole sync can't fix it. The errno
- # prefix and host are volatile, so we match the stable status text.
- "HTTP 403: Forbidden": "Snowflake refused the request with an HTTP 403 (forbidden). This usually means a network policy or firewall on your account is blocking PostHog's access, or your role's access to the data was revoked. Check your Snowflake network access rules and role grants, then resync.",
+ # Two different conditions produce it. At connect, or early in a sync, it is access
+ # denied: a network policy, firewall, or proxy blocks PostHog, or the role's grant on
+ # the data was revoked. Hours into a sync it is instead an expired result-chunk URL,
+ # because the pre-signed URLs that `result_batch.py::_download` fetches have a limited
+ # lifetime and a slow sync outlives them.
+ #
+ # Only the first condition is truly non-retryable. A fresh attempt re-executes the
+ # query and gets a new set of chunk URLs, so the expiry case would clear on retry the
+ # same way "HTTP 400: Bad Request" does below. Both stay here until the two can be told
+ # apart, because retrying a real access-denied 403 burns the whole attempt budget
+ # against a condition that only the customer can fix. The errno prefix and host are
+ # volatile, so we match the stable status text.
+ "HTTP 403: Forbidden": "Snowflake refused a request with an HTTP 403 (forbidden). If the sync ran for several hours before failing, the temporary link Snowflake gave us to download the query results expired. Resync to get a fresh one. If it failed soon after starting, check your Snowflake role grants and network access rules, then resync.",
}
def get_retryable_errors(self) -> set[str]:
@@ -337,7 +344,7 @@ class SnowflakeSource(SQLSource[SnowflakeSourceConfig]):
# Snowflake connector error 290400 (ER_HTTP_GENERAL_ERROR + 400): downloading a query
# result chunk got HTTP 400, which the connector's own `is_retryable_http_code` already
# retries with backoff before re-raising the plain `BadRequest` once its download retry
- # budget is exhausted (`result_batch.py::_download`). Unlike the persistent-403 case
+ # budget is exhausted (`result_batch.py::_download`). Unlike the access-denied 403 case
# above, every Temporal-level retry of `get_rows` opens a fresh connection and re-executes
# the query from scratch, getting a brand new set of chunk URLs — a stale one from the
# previous attempt doesn't carry over. Self-recovering, so keep retrying instead of
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/snowflake/tests/test_snowflake.py b/products/warehouse_sources/backend/temporal/data_imports/sources/snowflake/tests/test_snowflake.py
index 685f7fdb42f5..ba496d2f6664 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/snowflake/tests/test_snowflake.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/snowflake/tests/test_snowflake.py
@@ -823,10 +823,11 @@ class TestSnowflakeSourceNonRetryableErrors:
"290403: 290403: HTTP 403: Forbidden",
],
)
- def test_forbidden_403_is_non_retryable(self, source, error_msg):
+ def test_forbidden_403_is_non_retryable_and_names_both_causes(self, source, error_msg):
non_retryable = source.get_non_retryable_errors()
- is_non_retryable = any(pattern in error_msg for pattern in non_retryable.keys())
- assert is_non_retryable, f"Persistent HTTP 403 should be non-retryable: {error_msg}"
+ messages = [message for pattern, message in non_retryable.items() if pattern in error_msg]
+ assert messages, f"HTTP 403 should be non-retryable: {error_msg}"
+ assert all(message is not None and "expired" in message and "grants" in message for message in messages)
@pytest.mark.parametrize(
"error_msg",