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.

chore(azure-batch-exports): Raise non-retryable authorization failure (#62413)

Tomás Farías Santana6ce1de4a89f1
diff --git a/products/batch_exports/backend/temporal/destinations/azure_blob_batch_export.py b/products/batch_exports/backend/temporal/destinations/azure_blob_batch_export.py
index 36b1d1888fcf..fbeb5c053823 100644
--- a/products/batch_exports/backend/temporal/destinations/azure_blob_batch_export.py
+++ b/products/batch_exports/backend/temporal/destinations/azure_blob_batch_export.py
@@ -5,6 +5,7 @@ import dataclasses
from django.conf import settings
from azure.core.exceptions import HttpResponseError
+from azure.storage.blob import StorageErrorCode
from azure.storage.blob.aio import BlobServiceClient, ContainerClient, ExponentialRetry
from structlog.contextvars import bind_contextvars
from temporalio import activity, workflow
@@ -96,6 +97,14 @@ class MissingRequiredPermissionsError(Exception):
super().__init__("Missing required permissions to run this batch export")
+def _is_authorization_failure_response_error(err: HttpResponseError) -> bool:
+ """Check if the provided response error is an authorization failure.
+
+ 'error_code' is monkey-patched dynamically so we must use 'getattr' for type checkers.
+ """
+ return getattr(err, "error_code", None) == StorageErrorCode.AUTHORIZATION_FAILURE
+
+
@dataclasses.dataclass(kw_only=True)
class AzureBlobInsertInputs(BatchExportInsertInputs):
container_name: str
@@ -227,7 +236,7 @@ class AzureBlobConsumer(Consumer):
max_concurrency=self.max_concurrency,
)
except HttpResponseError as exc:
- if exc.error is not None and exc.error.code == "AuthorizationFailure":
+ if _is_authorization_failure_response_error(exc):
raise MissingRequiredPermissionsError()
else:
raise
@@ -253,7 +262,7 @@ class AzureBlobConsumer(Consumer):
overwrite=True,
)
except HttpResponseError as exc:
- if exc.error is not None and exc.error.code == "AuthorizationFailure":
+ if _is_authorization_failure_response_error(exc):
raise MissingRequiredPermissionsError()
else:
raise