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(snowflake): treat missing/unauthorized object as non-retryable (#63690)

Tom Owersbc849706820c
diff --git a/posthog/temporal/data_imports/sources/snowflake/source.py b/posthog/temporal/data_imports/sources/snowflake/source.py
index 59fd95fffbf7..ba52a72be0c7 100644
--- a/posthog/temporal/data_imports/sources/snowflake/source.py
+++ b/posthog/temporal/data_imports/sources/snowflake/source.py
@@ -206,6 +206,13 @@ class SnowflakeSource(SQLSource[SnowflakeSourceConfig]):
# rejects the connection because PostHog's egress IP isn't permitted. Retrying can never
# succeed until their admin allowlists our IPs, so stop retrying and surface what to do.
"is not allowed to access Snowflake": "Snowflake rejected the connection because a network policy (IP allowlist) on your account does not permit PostHog's IP address. Ask your Snowflake administrator to add PostHog's egress IP addresses to the network policy allowlist, then resync.",
+ # Snowflake error 002003 (SQLSTATE 42S02 for tables / 02000 for schemas): a table or
+ # schema the source syncs was dropped or renamed in Snowflake, or the role's grant on it
+ # was revoked, after the schema was discovered. The driver raises "<object> does not exist
+ # or not authorized" on `SHOW PRIMARY KEYS` / the data query. Retrying can never succeed
+ # until the user restores the object or re-grants access. The object name and query id in
+ # the message are volatile, so we match on the stable trailing phrase.
+ "does not exist or not authorized": "A table or schema this source syncs no longer exists in Snowflake, or your role is no longer authorized to access it. Check that the object still exists and that your Snowflake role has access, then resync.",
# Raised from the shared `evolve_pyarrow_schema` in `pipelines/pipeline/utils.py`
# when an integer column's source type was widened (e.g. a narrower NUMBER widened
# to a larger NUMBER/BIGINT) after the destination table was created with the
diff --git a/posthog/temporal/data_imports/sources/snowflake/tests/test_snowflake.py b/posthog/temporal/data_imports/sources/snowflake/tests/test_snowflake.py
index 2bd553d66393..cce1c8e54655 100644
--- a/posthog/temporal/data_imports/sources/snowflake/tests/test_snowflake.py
+++ b/posthog/temporal/data_imports/sources/snowflake/tests/test_snowflake.py
@@ -637,6 +637,22 @@ class TestSnowflakeSourceNonRetryableErrors:
is_non_retryable = any(pattern in error_msg for pattern in non_retryable.keys())
assert is_non_retryable, f"Network-policy block should be non-retryable: {error_msg}"
+ @pytest.mark.parametrize(
+ "error_msg",
+ [
+ # Table dropped/renamed or grant revoked (002003 / 42S02). Object name and query id vary.
+ "002003 (42S02): 01c511e7-0307-1937-0000-7c994379a9c2: SQL compilation error:\n"
+ "Table 'PRODUCTION.DBTNOVA.SCOPE_CATEGORIZATION' does not exist or not authorized.",
+ # Schema variant (002003 / 02000).
+ "002003 (02000): 01c4a15c-0105-a872-0002-113a44c42eaa: SQL compilation error:\n"
+ "Schema 'AXIOM.PRECOG_PRECOG_OPERATIONS_PRODUCT_US' does not exist or not authorized.",
+ ],
+ )
+ def test_object_not_found_or_unauthorized_is_non_retryable(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"Missing/unauthorized object error should be non-retryable: {error_msg}"
+
@pytest.mark.parametrize(
"error_msg",
[