Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/unreleased/fixed-20260716-092645.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: fixed
body: Handle HTTP 429 responses missing the Retry-After header instead of failing with an unexpected error
time: 2026-07-16T09:26:45+03:00
custom:
Author: ayeshurun
AuthorLink: https://github.com/ayeshurun
2 changes: 1 addition & 1 deletion src/fabric_cli/client/fab_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def do_request(
fab_constant.ERROR_NOT_FOUND,
)
case 429:
retry_after = int(response.headers["Retry-After"])
retry_after = get_polling_interval(response.headers)
utils_ui.print_info(
f"Rate limit exceeded. {attempt}º retrying attemp in {retry_after} seconds"
)
Comment thread
ayeshurun marked this conversation as resolved.
Expand Down
35 changes: 35 additions & 0 deletions tests/test_core/test_fab_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,41 @@ def __init__(self):
assert "ErrorCode" == excinfo.value.status_code


@patch.object(FabAuth(), "get_access_token", return_value="dummy-token")
def test_do_request_429_without_retry_after_header_retries_with_default_interval(
mock_get_token,
):
"""A 429 response missing the Retry-After header should fall back to the default
polling interval and retry instead of raising an unexpected KeyError."""

class DummyResponse:
def __init__(self, status_code, headers=None, text=""):
self.status_code = status_code
self.text = text
self.content = text.encode()
self.headers = headers if headers is not None else {}

# First response: throttled (429) with NO Retry-After header.
# Second response: success (200), so the retry loop can complete.
throttled = DummyResponse(429)
success = DummyResponse(200, text="{}")

dummy_args = Namespace()
dummy_args.uri = f"workspaces/{str(uuid.uuid4())}/items"
dummy_args.method = "get"
dummy_args.audience = None

with (
patch("requests.Session.request", side_effect=[throttled, success]),
patch("fabric_cli.client.fab_api_client.time.sleep") as mock_sleep,
):
response = do_request(dummy_args, hostname="custom.hostname.com")

assert response.status_code == 200
# Retried using the default polling interval (10s) rather than raising.
mock_sleep.assert_called_once_with(10)


@pytest.mark.parametrize(
"host_app_env, host_app_version_env, expected_suffix",
[
Expand Down
Loading