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 transient bitbucket 5xx errors as retryable (#117616)

posthog[bot]932cbcc40439
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bitbucket/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bitbucket/source.py
index fa2ce95f090c..8181757e63d8 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bitbucket/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bitbucket/source.py
@@ -151,6 +151,12 @@ Your credentials need the **repository**, **pullrequest**, **pipeline**, **proje
"Missing Atlassian account email or API token": "The Atlassian account email or API token is missing. Please update the source configuration.",
}
+ def get_retryable_errors(self) -> set[str]:
+ # A BitbucketRetryableError (429 or any 5xx) that survives _fetch_page's tenacity retry is a
+ # Bitbucket-side outage. Temporal retries the activity and resume state keeps the page, so log
+ # it as a warning rather than track it as an exception. Mirrors GitHub's equivalent case.
+ return {"Bitbucket API error (retryable)"}
+
def _get_auth(self, config: BitbucketSourceConfig) -> BitbucketAuth:
if config.auth_method.selection == "access_token":
if not config.auth_method.access_token:
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bitbucket/tests/test_bitbucket.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bitbucket/tests/test_bitbucket.py
index b58c4b958c73..449420510181 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bitbucket/tests/test_bitbucket.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bitbucket/tests/test_bitbucket.py
@@ -1,6 +1,6 @@
import dataclasses
from datetime import UTC, datetime
-from typing import Any
+from typing import Any, cast
import pytest
from unittest.mock import MagicMock, Mock
@@ -19,6 +19,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.bitbucket.
)
from products.warehouse_sources.backend.temporal.data_imports.sources.bitbucket.settings import BITBUCKET_ENDPOINTS
from products.warehouse_sources.backend.temporal.data_imports.sources.bitbucket.source import BitbucketSource
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.base import error_message_matches
from products.warehouse_sources.backend.temporal.data_imports.sources.common.testing import (
ScriptedResponse,
SourceDriver,
@@ -146,6 +147,20 @@ def test_fetch_page_rejects_off_origin_urls_without_sending_credentials(poisoned
session.get.assert_not_called()
+def test_fetch_page_exhausted_5xx_is_classified_retryable(monkeypatch):
+ # The raised message and BitbucketSource.get_retryable_errors are two halves of one contract:
+ # a rewording on either side sends a Bitbucket outage to error tracking as a PostHog exception.
+ monkeypatch.setattr(cast(Any, bitbucket._fetch_page).retry, "wait", lambda _: 0)
+ session = Mock()
+ session.get.return_value = Mock(status_code=503)
+
+ with pytest.raises(bitbucket.BitbucketRetryableError) as raised:
+ bitbucket._fetch_page(session, "https://api.bitbucket.org/2.0/repositories/ws", Mock())
+
+ assert error_message_matches(str(raised.value), BitbucketSource().get_retryable_errors())
+ assert not error_message_matches(str(raised.value), BitbucketSource().get_non_retryable_errors().keys())
+
+
def test_poisoned_resume_state_is_not_fetched():
result = _driver().run(
"repositories",