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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
fixes:
- |
Prevent ``wait_exponential`` from raising ``ValueError`` when dividing the
configured maximum wait by a large multiplier underflows to zero.
4 changes: 3 additions & 1 deletion tenacity/wait.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ def __call__(self, retry_state: "RetryCallState") -> float:
and self.max > 0
and self.exp_base > 1
and math.isfinite(self.max)
and exponent > math.log(self.max / self.multiplier, self.exp_base)
and exponent
> math.log(self.max, self.exp_base)
- math.log(self.multiplier, self.exp_base)
):
return max(max(0, self.min), self.max)
try:
Expand Down
4 changes: 4 additions & 0 deletions tests/test_tenacity.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,10 @@ def __pow__(self, exponent: float, modulo: int | None = None) -> float:
r = Retrying(wait=tenacity.wait_exponential(max=40, exp_base=ExplodingPower(2)))
self.assertEqual(r.wait(make_retry_state(50, 0)), 40)

def test_exponential_caps_when_max_multiplier_ratio_underflows(self) -> None:
r = Retrying(wait=tenacity.wait_exponential(multiplier=1e300, max=1e-100))
self.assertEqual(r.wait(make_retry_state(1, 0)), 1e-100)

def test_exponential_with_min_wait(self) -> None:
r = Retrying(wait=tenacity.wait_exponential(min=20))
self.assertEqual(r.wait(make_retry_state(1, 0)), 20)
Expand Down
Loading