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(data-warehouse): classify object store refusals in the delta layer (#104468)

Tom Owers2a1671915009
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/maintenance.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/maintenance.py
index f80c4c07cf00..127e88a81257 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/maintenance.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/maintenance.py
@@ -19,6 +19,7 @@ from products.warehouse_sources.backend.temporal.data_imports.pipelines.core.del
is_transient_maintenance_error,
)
from products.warehouse_sources.backend.temporal.data_imports.pipelines.core.delta.ops import (
+ ObjectStorePermissionDeniedError,
execute_with_conflict_retry,
)
@@ -122,15 +123,27 @@ class DeltaMaintenance:
await self._logger.adebug(json.dumps(compact_stats))
async def compact_table(self) -> None:
+ """Compact and vacuum unconditionally, after a non-CDC sync has loaded its rows.
+
+ An object-store refusal (see `run_scheduled` for why it does not fail the sync) is logged
+ and swallowed. Every other failure propagates to the caller, which decides how to report it.
+ """
table = await self._table.get_delta_table()
if table is None:
raise Exception("Deltatable not found")
- await self._compact(table)
- # Reuse the table already resolved above instead of re-fetching it: `get_delta_table`
- # is cached only opportunistically, so a re-fetch here can race a concurrent sync of a
- # different table evicting this table's cache entry and spuriously report it missing.
- await self._vacuum(table)
+ try:
+ await self._compact(table)
+ # Reuse the table already resolved above instead of re-fetching it: `get_delta_table`
+ # is cached only opportunistically, so a re-fetch here can race a concurrent sync of a
+ # different table evicting this table's cache entry and spuriously report it missing.
+ await self._vacuum(table)
+ except ObjectStorePermissionDeniedError:
+ await self._logger.awarning(
+ "Delta maintenance skipped: the object store denied the operation. The table's rows "
+ "are unaffected and the next maintenance pass retries the same cleanup."
+ )
+ return
await self._logger.adebug("Compacting and vacuuming complete")
async def vacuum_if_stale(self, last_vacuum_version: int | None, commit_threshold: int) -> int | None:
@@ -291,6 +304,14 @@ class DeltaMaintenance:
retries the same idempotent cleanup. A transient infra error (see
`is_transient_maintenance_error`) — an object-store hiccup, a racy concurrent-maintenance
DeltaError, or an app-DB connection blip — is logged at warning instead of captured.
+
+ An object-store refusal (see is_object_store_permission_denied) is logged at warning too.
+ Compaction and vacuuming only rewrite and reclaim files that the load has already committed,
+ so a refused pass leaves every live row queryable and costs the table nothing but a delayed
+ cleanup. It is a policy condition on our own bucket rather than a maintenance defect, so a
+ report per sync would say the same thing repeatedly about something no code change fixes.
+ The watermark is not persisted either, so the cadence re-attempts the vacuum on the next pass
+ instead of waiting another `commit_threshold` commits for a cleanup that never ran.
"""
try:
if is_cdc_companion:
@@ -311,6 +332,9 @@ class DeltaMaintenance:
await database_sync_to_async_pool(update_sync_type_config_keys)(
schema.id, schema.team_id, updates={watermark_key: new_version}
)
+ except ObjectStorePermissionDeniedError:
+ await self._logger.awarning("Delta maintenance skipped: the object store denied the operation")
+ return
except Exception as e:
if is_transient_maintenance_error(e):
await self._logger.awarning(f"Delta maintenance skipped: transient infra error: {e}")
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/ops.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/ops.py
index 277e897d426f..3d09a66a4f95 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/ops.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/ops.py
@@ -13,6 +13,49 @@ from products.warehouse_sources.backend.temporal.data_imports.pipelines.core.del
T = TypeVar("T")
+# An object store that refuses a read, a write or a delete surfaces the refusal in two shapes,
+# because two layers translate it:
+# - delta-rs maps a 403 from its Rust `object_store` crate onto `io::ErrorKind::PermissionDenied`,
+# whose `Display` is this one fixed English sentence, and its Python binding hands that back as a
+# bare `OSError`. A refusal that happens while a commit is being written arrives instead as a
+# `CommitFailedError` wrapping the same sentence, because delta-rs maps every
+# `DeltaTableError::Transaction` onto that class regardless of what the transaction failed on.
+# - s3fs translates an explicit S3 `AccessDenied` response code into `PermissionError("Access
+# Denied")`.
+# Both mean the bucket policy or the worker's role refuses the call on that key, so running the same
+# call again returns the same refusal. A bodyless 403 is deliberately not matched: AWS omits the
+# error code from a HEAD response, so s3fs raises `PermissionError("Forbidden")` for a brief
+# credential-resolution race as well as for a real refusal, and `_purge_s3_prefix` still retries it.
+OBJECT_STORE_PERMISSION_DENIED_ERRORS = (
+ "The operation lacked the necessary privileges to complete",
+ "Access Denied",
+)
+
+# Reaches the customer as the sync run's error text, so it names neither the bucket nor the object
+# key. The data warehouse bucket is PostHog's own and the worker authenticates to it with its own
+# role, which means a refusal here is never caused by the customer's source or credentials.
+OBJECT_STORE_PERMISSION_DENIED_MESSAGE = (
+ "PostHog could not read or write this table's files in its own storage. This is a problem on "
+ "PostHog's side, not with your source. Contact support if it keeps happening."
+)
+
+
+class ObjectStorePermissionDeniedError(Exception):
+ """The data warehouse bucket refused a read, a write or a delete.
+
+ Raised in place of the raw `OSError`/`PermissionError`/`CommitFailedError` so the delta layer
+ can treat a refusal as its own outcome. It is not a commit conflict and not a transient blip, so
+ every retry budget in this package must let it through on the first attempt instead of repeating
+ a call that is already refused.
+ """
+
+
+def is_object_store_permission_denied(error: BaseException) -> bool:
+ return isinstance(error, OSError | deltalake.exceptions.DeltaError) and any(
+ needle in str(error) for needle in OBJECT_STORE_PERMISSION_DENIED_ERRORS
+ )
+
+
def delta_merge_spill_kwargs() -> dict[str, int]:
"""delta-rs `merge` kwargs that let DataFusion spill to disk instead of OOMing on large merges.
@@ -53,12 +96,24 @@ async def execute_with_conflict_retry(
See DELTA_MERGE_CONFLICT_RETRIES for why this can't rely on delta-rs's own retry budget. Also
retries `is_invalid_version_race` — the same race surfacing as a plain `DeltaError` rather than
`CommitFailedError` because delta-rs's Python binding doesn't give that variant its own class.
+
+ An object-store refusal (see is_object_store_permission_denied) is raised as
+ `ObjectStorePermissionDeniedError` on the first attempt, so a refused vacuum or compaction can't
+ be mistaken for a conflict and spend the budget on calls that are already refused.
"""
attempt = 0
while True:
try:
return await asyncio.to_thread(operation_fn)
- except deltalake.exceptions.DeltaError as e:
+ except (OSError, deltalake.exceptions.DeltaError) as e:
+ if is_object_store_permission_denied(e):
+ # The raw error names the object key it was refused on, which must stay out of the
+ # customer-facing message, so it is kept only as the cause. The exception class
+ # tells which layer translated the refusal, without repeating the key.
+ await logger.awarning(f"{operation_name}: the object store denied the operation ({type(e).__name__})")
+ raise ObjectStorePermissionDeniedError(OBJECT_STORE_PERMISSION_DENIED_MESSAGE) from e
+ if not isinstance(e, deltalake.exceptions.DeltaError):
+ raise
if not isinstance(e, deltalake.exceptions.CommitFailedError) and not is_invalid_version_race(e):
raise
if attempt >= DELTA_MERGE_CONFLICT_RETRIES:
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/table.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/table.py
index 86f5d0ab6f51..d7c16ee9336a 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/table.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/table.py
@@ -21,6 +21,11 @@ from products.warehouse_sources.backend.temporal.data_imports.pipelines.core.del
is_transient_delta_maintenance_error,
is_transient_object_store_error,
)
+from products.warehouse_sources.backend.temporal.data_imports.pipelines.core.delta.ops import (
+ OBJECT_STORE_PERMISSION_DENIED_MESSAGE,
+ ObjectStorePermissionDeniedError,
+ is_object_store_permission_denied,
+)
# _purge_s3_prefix is idempotent (every step is existence-gated), so retrying it whole after a brief
# backoff is as safe as retrying a single failed call, and simpler.
@@ -40,6 +45,10 @@ def _is_retryable_purge_error(error: OSError) -> bool:
NoCredentialsError above, just surfacing as an explicit S3-side denial instead of a local
resolution failure. Retrying the same bounded budget lets that race self-heal; a persistent
misconfiguration still raises once the budget is exhausted, since this only defers the error.
+
+ The `PermissionError` clause only ever sees a bodyless 403, because `_purge_s3_prefix` classifies
+ a response that does carry an explicit `AccessDenied` code before reaching here (see
+ is_object_store_permission_denied) and raises on it instead of retrying.
"""
return is_transient_object_store_error(error) or isinstance(error, PermissionError)
@@ -56,6 +65,12 @@ async def _purge_s3_prefix(s3: Any, uri: str) -> None:
await _purge_s3_prefix_once(s3, uri)
return
except OSError as e:
+ if is_object_store_permission_denied(e):
+ # S3 only returns an explicit AccessDenied code when a policy refuses the call, so
+ # every remaining attempt would make the same refused DeleteObjects calls and only
+ # delay the failure. Raise a typed error on the first one, and keep the object key
+ # it names out of the message the customer reads.
+ raise ObjectStorePermissionDeniedError(OBJECT_STORE_PERMISSION_DENIED_MESSAGE) from e
attempt += 1
if attempt >= _PURGE_S3_PREFIX_MAX_ATTEMPTS or not _is_retryable_purge_error(e):
raise
@@ -189,16 +204,36 @@ class DeltaTableRef:
return self._get_credentials()
async def _capture_unless_transient(self, e: Exception) -> None:
- """capture_exception unless `e` is a known-transient object-store blip (see
- is_transient_object_store_error) or a concurrent-purge race on `_delta_log` (see
- is_transient_delta_maintenance_error — the open below can lose that same race a maintenance
- pass can) — those recover on retry and aren't a defect, so reporting them to error tracking
- is just noise. A transient blip is re-raised as TransientObjectStoreError instead of letting
- the original propagate: the activity interceptor reports any uncaught activity exception
- unless it's a NonReportableError, so a bare re-raise here would still mint a fresh issue at
- that boundary. Never suppresses the re-raise itself, so Temporal's activity retry policy is
- unaffected either way.
+ """capture_exception unless `e` is already classified as something other than a defect.
+
+ A known-transient object-store blip (see is_transient_object_store_error) or a
+ concurrent-purge race on `_delta_log` (see is_transient_delta_maintenance_error, because the
+ open below can lose the same race a maintenance pass can) recovers on retry, so reporting it
+ to error tracking is just noise. Both are re-raised as TransientObjectStoreError instead of
+ letting the original propagate, because the activity interceptor reports any uncaught
+ activity exception unless it is a NonReportableError, which TransientObjectStoreError is, so
+ a bare re-raise here would still mint a fresh issue at that boundary.
+
+ An object-store refusal (see is_object_store_permission_denied) is re-raised as
+ ObjectStorePermissionDeniedError, which is not a NonReportableError: a refusal on our own
+ bucket needs a human, so it is still reported, once, under a message that names no object key.
+
+ Never suppresses the re-raise itself, so Temporal's activity retry policy is unaffected
+ whichever branch runs.
"""
+ if is_object_store_permission_denied(e):
+ # The bucket refused the read, which is a policy condition on our own storage rather
+ # than a defect in this code or a corrupt table. Raising the typed error instead of
+ # capturing here leaves one report at the activity boundary rather than two, and its
+ # message carries no `_delta_log` key, so the customer's error text stays free of the
+ # object key and error tracking gets one issue instead of one per table.
+ #
+ # Classified before the transient check, because delta-rs prefixes many object-store
+ # errors with "Generic S3 error", which that check treats as transient on its own. A
+ # refusal that arrives under that prefix is still definitive, and retrying it would
+ # hide it behind Temporal's retry policy until the activity gave up.
+ await self._logger.aerror(f"get_delta_table: the object store denied the read ({type(e).__name__})")
+ raise ObjectStorePermissionDeniedError(OBJECT_STORE_PERMISSION_DENIED_MESSAGE) from e
if is_transient_object_store_error(e) or is_transient_delta_maintenance_error(e):
await self._logger.awarning(f"get_delta_table: transient object-store error, not reporting: {e}")
raise TransientObjectStoreError(str(e)) from e
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/test/test_maintenance.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/test/test_maintenance.py
index 69a95a77e1ea..ee7be716f195 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/test/test_maintenance.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/test/test_maintenance.py
@@ -8,6 +8,9 @@ from products.warehouse_sources.backend.temporal.data_imports.pipelines.core.del
COMPACT_OFFSET_OVERFLOW_RETRIES,
DeltaMaintenance,
)
+from products.warehouse_sources.backend.temporal.data_imports.pipelines.core.delta.ops import (
+ ObjectStorePermissionDeniedError,
+)
from products.warehouse_sources.backend.temporal.data_imports.pipelines.core.delta.test.helpers import make_logger
_MAINTENANCE_MODULE = "products.warehouse_sources.backend.temporal.data_imports.pipelines.core.delta.maintenance"
@@ -148,6 +151,26 @@ class TestCompactTable:
mock_delta.optimize.compact.assert_called_once()
mock_delta.vacuum.assert_called_once()
+ @pytest.mark.asyncio
+ async def test_refused_vacuum_does_not_fail_the_sync(self):
+ # Vacuum only reclaims files the load already tombstoned, so a bucket that refuses the delete
+ # leaves every live row queryable. compact_table's caller reports anything it raises, which
+ # turned a refused cleanup into a reported failure on a sync that had loaded its rows fine.
+ mock_delta = MagicMock()
+ mock_delta.optimize.compact = MagicMock(return_value={})
+ mock_delta.vacuum = MagicMock(
+ side_effect=OSError(
+ "Kernel error -> The operation lacked the necessary privileges to complete for path "
+ "warehouse/team_42_source_7/orders/part-00003.parquet"
+ )
+ )
+ maintenance = _make_maintenance(mock_delta)
+
+ await maintenance.compact_table()
+
+ # One attempt only: a refusal must not be retried as though it were a commit conflict.
+ mock_delta.vacuum.assert_called_once()
+
@pytest.mark.asyncio
async def test_retries_compact_on_commit_conflict_then_succeeds(self):
# compact_table's optimize.compact() commits a REMOVE+ADD when rewriting fragmented files —
@@ -436,6 +459,12 @@ class TestRunScheduled:
),
False,
),
+ # A refused read/write/delete on our own bucket is a policy condition rather than a
+ # maintenance defect, and no code change fixes it, so reporting it once per sync says
+ # the same thing repeatedly. The watermark assertion below is what keeps the cadence
+ # re-attempting the vacuum instead of waiting another commit_threshold commits for a
+ # cleanup that never ran.
+ ("object_store_refusal_warned_only", ObjectStorePermissionDeniedError("denied"), False),
]
)
@pytest.mark.asyncio
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/test/test_ops.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/test/test_ops.py
index cfa07490210e..f0c675541bc3 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/test/test_ops.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/test/test_ops.py
@@ -8,6 +8,7 @@ from parameterized import parameterized
from products.warehouse_sources.backend.temporal.data_imports.pipelines.core.delta.ops import (
DELTA_MERGE_CONFLICT_RETRIES,
+ ObjectStorePermissionDeniedError,
delta_merge_spill_kwargs,
execute_with_conflict_retry,
)
@@ -131,3 +132,51 @@ class TestExecuteWithConflictRetry:
operation_fn.assert_called_once()
table.update_incremental.assert_not_called()
+
+ @parameterized.expand(
+ [
+ # delta-rs maps a 403 from its Rust object_store crate onto io::ErrorKind::PermissionDenied
+ # and hands the fixed sentence back as a bare OSError.
+ (
+ "kernel_privileges_oserror",
+ OSError(
+ "Kernel error -> The operation lacked the necessary privileges to complete for path "
+ "warehouse/team_42_source_7/orders/part-00003.parquet"
+ ),
+ ),
+ # The same refusal during the commit itself arrives as CommitFailedError, because delta-rs
+ # maps every DeltaTableError::Transaction onto that class whatever the transaction failed on.
+ # Without classifying the text first, this reads as a conflict and spends the whole budget.
+ (
+ "refusal_wrapped_in_commit_failed",
+ deltalake.exceptions.CommitFailedError(
+ "Object store error: Generic S3 error: The operation lacked the necessary privileges "
+ "to complete for path warehouse/team_42_source_7/orders/_delta_log/00000000000000000012.json"
+ ),
+ ),
+ # s3fs translates an explicit S3 AccessDenied response code into PermissionError.
+ ("s3fs_access_denied", PermissionError("Access Denied")),
+ ]
+ )
+ @pytest.mark.asyncio
+ async def test_object_store_refusal_is_typed_and_not_retried(self, _case: str, error: Exception):
+ # A refused read, write or delete is not a race, so re-running the operation against a
+ # refreshed table makes the same refused calls. Regression coverage for the refusal reaching
+ # the caller as a raw OSError (which no retry budget in this package classifies) and for a
+ # refusal wrapped in CommitFailedError burning the conflict budget before it does.
+ table = MagicMock()
+ operation_fn = MagicMock(side_effect=error)
+
+ with pytest.raises(ObjectStorePermissionDeniedError) as exc_info:
+ await execute_with_conflict_retry(table, operation_fn, "op", make_logger())
+
+ assert exc_info.value.__cause__ is error
+ # The message reaches the customer as the sync run's error text, so the object key the raw
+ # error names must not survive into it.
+ assert "warehouse/" not in str(exc_info.value)
+ # It also reaches every source's non-retryable-error patterns (see external_data_job.py),
+ # many of which match "access denied". A message carrying that phrase pauses the schema and
+ # tells the customer to go fix credentials that are working.
+ assert "access denied" not in str(exc_info.value).lower()
+ operation_fn.assert_called_once()
+ table.update_incremental.assert_not_called()
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/test/test_table.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/test/test_table.py
index 5a9ec33e6136..9b818c6ef735 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/test/test_table.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/test/test_table.py
@@ -11,6 +11,9 @@ from parameterized import parameterized
from products.warehouse_sources.backend.temporal.data_imports.pipelines.core.delta.errors import (
TransientObjectStoreError,
)
+from products.warehouse_sources.backend.temporal.data_imports.pipelines.core.delta.ops import (
+ ObjectStorePermissionDeniedError,
+)
from products.warehouse_sources.backend.temporal.data_imports.pipelines.core.delta.table import (
_PURGE_S3_PREFIX_MAX_ATTEMPTS,
DeltaTableRef,
@@ -177,9 +180,9 @@ class TestGetDeltaTableUnrecoverableErrors:
patch(f"{module}.deltalake.DeltaTable") as mock_delta_table,
patch(f"{module}.capture_exception") as mock_capture,
):
- mock_delta_table.is_deltatable.side_effect = OSError("Access Denied: not authorized to list bucket")
+ mock_delta_table.is_deltatable.side_effect = OSError("unexpected end of stream while reading response")
- with pytest.raises(OSError, match="Access Denied"):
+ with pytest.raises(OSError, match="unexpected end of stream"):
await table_ref.get_delta_table()
mock_capture.assert_called_once()
@@ -217,6 +220,38 @@ class TestGetDeltaTableUnrecoverableErrors:
cast(AsyncMock, table_ref._logger.awarning).assert_awaited_once()
assert table_ref.is_first_sync is False
+ @pytest.mark.asyncio
+ async def test_object_store_refusal_is_typed_and_not_captured_inline(self):
+ """The bucket refusing the read is a policy condition on PostHog's own storage, not a defect
+ in this code and not a corrupt table. Capturing inline here and then reraising the raw
+ OSError reported the same refusal twice, once from this call and once from the activity
+ interceptor, and the raw message names the `_delta_log` key it was refused on, which both
+ leaks the object key into the customer's error text and fingerprints into its own
+ error-tracking issue per table. Raising the typed error leaves one report, with a message
+ that names no key."""
+ table_ref = DeltaTableRef(resource_name="t", job=MagicMock(), logger=make_logger())
+ delta_uri = "s3://bucket/team_id/job_id/t"
+
+ original_error = OSError(
+ "Kernel error -> The operation lacked the necessary privileges to complete for path "
+ "warehouse/team_42_source_7/orders/_delta_log/00000000000000000012.json"
+ )
+ module = "products.warehouse_sources.backend.temporal.data_imports.pipelines.core.delta.table"
+ with (
+ patch.object(table_ref, "_get_delta_table_uri", AsyncMock(return_value=delta_uri)),
+ patch(f"{module}.deltalake.DeltaTable") as mock_delta_table,
+ patch(f"{module}.capture_exception") as mock_capture,
+ ):
+ mock_delta_table.is_deltatable.side_effect = original_error
+
+ with pytest.raises(ObjectStorePermissionDeniedError) as exc_info:
+ await table_ref.get_delta_table()
+
+ assert exc_info.value.__cause__ is original_error
+ assert "_delta_log" not in str(exc_info.value)
+ mock_capture.assert_not_called()
+ assert table_ref.is_first_sync is False
+
@pytest.mark.asyncio
async def test_open_transient_delta_log_race_is_not_captured_but_still_reraised(self):
"""A concurrent `reset_table` purge (a full_refresh sync, or this same open racing another
@@ -300,7 +335,7 @@ class TestIsTableCorrupted:
assert result is expected
-class TestPurgeS3PrefixRetriesPermissionError:
+class TestPurgeS3PrefixPermissionErrors:
_MODULE = "products.warehouse_sources.backend.temporal.data_imports.pipelines.core.delta.table"
# A HeadObject 403 never carries the underlying S3 error code in its body (AWS omits it for HEAD
@@ -321,16 +356,29 @@ class TestPurgeS3PrefixRetriesPermissionError:
assert mock_once.await_count == 2
+ @parameterized.expand(
+ [
+ # A bodyless 403 keeps the whole budget, because it can still be the race above.
+ ("bodyless_403_spends_the_budget", "Forbidden", _PURGE_S3_PREFIX_MAX_ATTEMPTS, PermissionError),
+ # S3 only returns an explicit AccessDenied code when a policy refuses the call, so the
+ # remaining attempts would make the same refused DeleteObjects calls. They only delay the
+ # failure by the backoff, which is why this one has to fail on the first attempt and say
+ # what it is instead of surfacing as a bare PermissionError.
+ ("explicit_access_denied_fails_once", "Access Denied", 1, ObjectStorePermissionDeniedError),
+ ]
+ )
@pytest.mark.asyncio
- async def test_gives_up_after_max_attempts_on_persistent_permission_error(self):
+ async def test_persistent_permission_error(
+ self, _case: str, message: str, expected_attempts: int, expected_error: type[Exception]
+ ):
with (
patch(
f"{self._MODULE}._purge_s3_prefix_once",
- new=AsyncMock(side_effect=PermissionError("Forbidden")),
+ new=AsyncMock(side_effect=PermissionError(message)),
) as mock_once,
patch(f"{self._MODULE}.asyncio.sleep", new=AsyncMock()),
):
- with pytest.raises(PermissionError):
+ with pytest.raises(expected_error):
await _purge_s3_prefix(MagicMock(), "s3://bucket/prefix")
- assert mock_once.await_count == _PURGE_S3_PREFIX_MAX_ATTEMPTS
+ assert mock_once.await_count == expected_attempts