Skip to content

Commit b8ab63d

Browse files
Treat signed string status metadata as unknown retryable
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 219bc1c commit b8ab63d

File tree

2 files changed

+52
-5
lines changed

2 files changed

+52
-5
lines changed

hyperbrowser/client/polling.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,7 @@ def _normalize_status_code_for_retry(status_code: object) -> Optional[int]:
208208
return None
209209
if len(normalized_status) > _MAX_STATUS_CODE_TEXT_LENGTH:
210210
return None
211-
if normalized_status[0] in {"+", "-"}:
212-
digits = normalized_status[1:]
213-
else:
214-
digits = normalized_status
215-
if not digits or not digits.isascii() or not digits.isdigit():
211+
if not normalized_status.isascii() or not normalized_status.isdigit():
216212
return None
217213
try:
218214
return int(normalized_status, 10)

tests/test_polling.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,34 @@ async def get_status() -> str:
524524
asyncio.run(run())
525525

526526

527+
def test_poll_until_terminal_status_async_handles_signed_string_status_codes_as_retryable_unknown():
528+
async def run() -> None:
529+
attempts = {"count": 0}
530+
531+
async def get_status() -> str:
532+
attempts["count"] += 1
533+
if attempts["count"] < 3:
534+
raise HyperbrowserError(
535+
"signed status code metadata",
536+
status_code="+400", # type: ignore[arg-type]
537+
)
538+
return "completed"
539+
540+
status = await poll_until_terminal_status_async(
541+
operation_name="async poll signed status metadata retries",
542+
get_status=get_status,
543+
is_terminal_status=lambda value: value == "completed",
544+
poll_interval_seconds=0.0001,
545+
max_wait_seconds=1.0,
546+
max_status_failures=5,
547+
)
548+
549+
assert status == "completed"
550+
assert attempts["count"] == 3
551+
552+
asyncio.run(run())
553+
554+
527555
def test_poll_until_terminal_status_async_handles_unicode_digit_like_status_codes_as_retryable():
528556
async def run() -> None:
529557
attempts = {"count": 0}
@@ -1101,6 +1129,29 @@ def operation() -> str:
11011129
assert attempts["count"] == 3
11021130

11031131

1132+
def test_retry_operation_handles_signed_string_status_codes_as_retryable_unknown():
1133+
attempts = {"count": 0}
1134+
1135+
def operation() -> str:
1136+
attempts["count"] += 1
1137+
if attempts["count"] < 3:
1138+
raise HyperbrowserError(
1139+
"signed status code metadata",
1140+
status_code="-400", # type: ignore[arg-type]
1141+
)
1142+
return "ok"
1143+
1144+
result = retry_operation(
1145+
operation_name="sync retry signed status metadata",
1146+
operation=operation,
1147+
max_attempts=5,
1148+
retry_delay_seconds=0.0001,
1149+
)
1150+
1151+
assert result == "ok"
1152+
assert attempts["count"] == 3
1153+
1154+
11041155
def test_retry_operation_handles_unicode_digit_like_status_codes_as_retryable():
11051156
attempts = {"count": 0}
11061157

0 commit comments

Comments
 (0)