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-sources): recognize pyarrow's generic missing-file error in account-property staging (#109585)

Tom Owers81858b69f20b
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/account_property_row_sink.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/account_property_row_sink.py
index fc59ea922012..eb478c16e1e4 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/account_property_row_sink.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/account_property_row_sink.py
@@ -33,10 +33,17 @@ from products.warehouse_sources.backend.temporal.data_imports.pipelines.core.del
ABANDONED_STAGED_PREFIX_TTL = timedelta(days=7)
_PARQUET_BATCH_SIZE = 50_000
-# Same fixed AWS message pyarrow's S3FileSystem surfaces as a bare OSError for a GetObject against a
-# key that no longer exists — matched the same way as the equivalent NoSuchKey race in
+# Two distinct message shapes pyarrow's S3FileSystem can raise as a bare OSError for the same
+# missing-key condition, depending on which call hit it: a direct GetObject (the raw AWS text) vs.
+# `open_input_file`'s own preflight `GetFileInfo` check, which formats a fixed, backend-agnostic
+# "not found" message instead of surfacing the AWS error. `_stage_committed_files` only ever calls
+# `open_input_file` (random-access reads), so only the second shape is reachable from here in
+# practice — matched the same way as the equivalent NoSuchKey race in
# workflow_activities/repartition_table.py.
-_MISSING_OBJECT_ERROR_NEEDLE = "the specified key does not exist"
+_MISSING_OBJECT_ERROR_NEEDLES = (
+ "the specified key does not exist",
+ "path does not exist",
+)
# delta-rs raises this DeltaError, instead of the OSError above, when the pinned version wasn't
# vacuumed but the whole table was reset and recommitted from scratch by a later materialize run
@@ -48,7 +55,10 @@ _LOG_SEGMENT_VERSION_MISMATCH_NEEDLE = "not the same as the specified end versio
def _is_missing_object_error(error: BaseException) -> bool:
- return isinstance(error, OSError) and _MISSING_OBJECT_ERROR_NEEDLE in str(error).lower()
+ if not isinstance(error, OSError):
+ return False
+ message = str(error).lower()
+ return any(needle in message for needle in _MISSING_OBJECT_ERROR_NEEDLES)
def _is_stale_pinned_version_error(error: BaseException) -> bool:
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/account_property_row_sink_test.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/account_property_row_sink_test.py
index c4bd893cf8bb..21f1208abbd5 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/account_property_row_sink_test.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/account_property_row_sink_test.py
@@ -23,6 +23,7 @@ from products.warehouse_sources.backend.temporal.data_imports.pipelines.core.acc
from products.warehouse_sources.backend.temporal.data_imports.pipelines.core.account_property_row_sink import (
ABANDONED_STAGED_PREFIX_TTL,
AccountPropertyRowSink,
+ _is_missing_object_error,
)
_MODULE = "products.warehouse_sources.backend.temporal.data_imports.pipelines.core.account_property_row_sink"
@@ -53,6 +54,24 @@ def test_all_account_property_artifacts_use_the_data_modeling_prefix() -> None:
assert all(path.startswith(f"{expected_root}/") for path in paths)
+ ("error", "expected"),
+ [
+ # `open_input_file`'s preflight GetFileInfo check (the only path `_stage_committed_files`
+ # exercises) surfaces a missing key through this backend-agnostic pyarrow message, not the
+ # raw AWS text below.
+ (OSError(2, "Path does not exist 'bucket/key'. Detail: [errno 2] No such file or directory"), True),
+ # A direct GetObject 404 raises this raw AWS text instead — kept recognized too, matching the
+ # equivalent classifier in workflow_activities/repartition_table.py.
+ (OSError("AWS Error NO_SUCH_KEY during GetObject operation: The specified key does not exist."), True),
+ (OSError("Permission denied: bucket policy forbids this operation"), False),
+ (ValueError("Path does not exist 'bucket/key'"), False),
+ ],
+)
+def test_is_missing_object_error_classifies_both_pyarrow_message_shapes(error: Exception, expected: bool) -> None:
+ assert _is_missing_object_error(error) is expected
+
+
class _S3ClientContext:
def __init__(self, client: MagicMock) -> None:
self.client = client
@@ -165,8 +184,10 @@ async def test_stages_an_exact_delta_snapshot_after_materialization() -> None:
async def test_stage_delta_snapshot_falls_back_to_latest_version_after_a_vacuum_race() -> None:
# The pinned delta_version can sit queued behind the staging child workflow for hours. If the
# same view materializes again in the meantime, its vacuum can reclaim that version's files
- # before we read them (AWS NO_SUCH_KEY). Staging must recover by re-reading whatever is
- # committed now instead of failing the whole sync.
+ # before we read them. `_stage_committed_files` reads via `open_input_file` (random access), whose
+ # preflight `GetFileInfo` check surfaces a missing key as pyarrow's own generic "not found" message
+ # rather than the raw AWS NoSuchKey text a direct GetObject would raise. Staging must recover by
+ # re-reading whatever is committed now instead of failing the whole sync.
sink = _sink()
fresh_table = pa.table({"organization_id": ["org-1"], "mrr": [100]})
fresh_output = pa.BufferOutputStream()
@@ -183,8 +204,8 @@ async def test_stage_delta_snapshot_falls_back_to_latest_version_after_a_vacuum_
def _open_input_file(path):
if path == "data-warehouse/dlt/vacuumed.parquet":
raise OSError(
- "AWS Error NO_SUCH_KEY during GetObject operation: The specified key does not "
- "exist. (Request ID: TESTREQUESTID)"
+ 2,
+ f"Path does not exist '{path}'. Detail: [errno 2] No such file or directory",
)
return pa.BufferReader(fresh_output.getvalue())