Skip to content

Commit ede7d0c

Browse files
Treat int-subclass status metadata as unknown in polling retries
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent f1fb508 commit ede7d0c

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

hyperbrowser/client/polling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ def _decode_ascii_bytes_like(value: object) -> Optional[str]:
381381
def _normalize_status_code_for_retry(status_code: object) -> Optional[int]:
382382
if isinstance(status_code, bool):
383383
return None
384-
if isinstance(status_code, int):
384+
if type(status_code) is int:
385385
return status_code
386386
status_text: Optional[str] = None
387387
if isinstance(status_code, memoryview):

tests/test_polling.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,6 +1659,32 @@ def operation() -> str:
16591659
assert attempts["count"] == 3
16601660

16611661

1662+
def test_retry_operation_handles_integer_subclass_status_codes_as_retryable_unknown():
1663+
class _StatusCodeInt(int):
1664+
pass
1665+
1666+
attempts = {"count": 0}
1667+
1668+
def operation() -> str:
1669+
attempts["count"] += 1
1670+
if attempts["count"] < 3:
1671+
raise HyperbrowserError(
1672+
"int-subclass status code",
1673+
status_code=_StatusCodeInt(429), # type: ignore[arg-type]
1674+
)
1675+
return "ok"
1676+
1677+
result = retry_operation(
1678+
operation_name="sync retry int-subclass status code",
1679+
operation=operation,
1680+
max_attempts=5,
1681+
retry_delay_seconds=0.0001,
1682+
)
1683+
1684+
assert result == "ok"
1685+
assert attempts["count"] == 3
1686+
1687+
16621688
def test_retry_operation_handles_signed_string_status_codes_as_retryable_unknown():
16631689
attempts = {"count": 0}
16641690

@@ -2472,6 +2498,35 @@ async def operation() -> str:
24722498
asyncio.run(run())
24732499

24742500

2501+
def test_retry_operation_async_handles_integer_subclass_status_codes_as_retryable_unknown():
2502+
class _StatusCodeInt(int):
2503+
pass
2504+
2505+
async def run() -> None:
2506+
attempts = {"count": 0}
2507+
2508+
async def operation() -> str:
2509+
attempts["count"] += 1
2510+
if attempts["count"] < 3:
2511+
raise HyperbrowserError(
2512+
"int-subclass status code",
2513+
status_code=_StatusCodeInt(429), # type: ignore[arg-type]
2514+
)
2515+
return "ok"
2516+
2517+
result = await retry_operation_async(
2518+
operation_name="async retry int-subclass status code",
2519+
operation=operation,
2520+
max_attempts=5,
2521+
retry_delay_seconds=0.0001,
2522+
)
2523+
2524+
assert result == "ok"
2525+
assert attempts["count"] == 3
2526+
2527+
asyncio.run(run())
2528+
2529+
24752530
def test_retry_operation_async_retries_bytearray_rate_limit_errors():
24762531
async def run() -> None:
24772532
attempts = {"count": 0}

0 commit comments

Comments
 (0)