: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(data-imports): retry a bodyless S3 403 when copying files to the query folder (#104912)
Tom Owersf1576ed1fad8
diff --git a/products/warehouse_sources/backend/temporal/data_imports/tests/test_util.py b/products/warehouse_sources/backend/temporal/data_imports/tests/test_util.pyindex 8240e0a4193e..2df77b55704d 100644--- a/products/warehouse_sources/backend/temporal/data_imports/tests/test_util.py+++ b/products/warehouse_sources/backend/temporal/data_imports/tests/test_util.py@@ -245,6 +245,12 @@ class TestPrepareS3FilesForQuerying:# translates every back-off response code to, so a store whose wording the message# needles don't match is still retried rather than failing the sync.("throttled", OSError(errno.EBUSY, "Reduce your request rate for this prefix.")),+ # AWS omits the error code from a HeadObject response body, so s3fs's _cp_file (which+ # HEADs the destination) raises the same bare PermissionError for a brief+ # credential-resolution race as it does for a genuine denial. Regression: this used to+ # fail the whole sync on the first attempt instead of retrying, unlike the identical+ # ambiguity _purge_s3_prefix already retries.+ ("credential_resolution_race", PermissionError("Forbidden")),])async def test_retries_transient_s3_error_during_copy(self, name: str, transient_error: OSError):diff --git a/products/warehouse_sources/backend/temporal/data_imports/util.py b/products/warehouse_sources/backend/temporal/data_imports/util.pyindex c95b049441e7..49eb3a957430 100644--- a/products/warehouse_sources/backend/temporal/data_imports/util.py+++ b/products/warehouse_sources/backend/temporal/data_imports/util.py@@ -272,6 +272,9 @@ async def prepare_s3_files_for_querying(from products.warehouse_sources.backend.temporal.data_imports.pipelines.core.delta.errors import ( # noqa: PLC0415 — keeps the heavy deltalake dep off this module's top-level import pathis_transient_object_store_error,)+ from products.warehouse_sources.backend.temporal.data_imports.pipelines.core.delta.ops import ( # noqa: PLC0415 — keeps the heavy deltalake dep off this module's top-level import path+ is_object_store_permission_denied,+ )attempt = 0while True:@@ -308,11 +311,21 @@ async def prepare_s3_files_for_querying(level="error",)except OSError as e:+ if is_object_store_permission_denied(e):+ # An explicit AccessDenied/lacked-privileges response is never a race - every+ # retry would repeat the same refused call, so fail on the first attempt.+ raise S3OperationError("copy this table's files into its query folder", e)# s3fs wraps a CopyObject/PutObject 5xx (e.g. S3's InternalError, already retried to# exhaustion at the boto layer) as a plain OSError. That's a blip on S3's side, not a# bug here - retry the whole (idempotent) copy batch with backoff before giving up.+ # A bare PermissionError is included too: AWS omits the error code from a HeadObject+ # response body, so s3fs's _cp_file (which HEADs the destination) raises the same+ # PermissionError("Forbidden") for a brief credential-resolution race as it does for a+ # genuine denial (is_object_store_permission_denied only catches the latter, via an+ # explicit code). _purge_s3_prefix retries this same ambiguous case for the same+ # reason - see _is_retryable_purge_error.if attempt >= _COPY_FILES_MAX_ATTEMPTS or not (- is_transient_object_store_error(e) or _is_s3_throttling_error(e)+ is_transient_object_store_error(e) or _is_s3_throttling_error(e) or isinstance(e, PermissionError)):# Either the failure needs a human (denied permissions, a storage backend with no# free space) or the retries ran out. Both leave the raw s3fs message, so re-raise