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,8 @@
---
fixes:
- |
``wait_chain()`` now raises ``ValueError`` at construction time when
called with no strategies, instead of raising a confusing
``IndexError`` from ``__call__`` the first time it is used. Empty
wait chains have no useful behaviour, so failing early gives a
clearer error message.
2 changes: 2 additions & 0 deletions tenacity/wait.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ def wait_chained():
"""

def __init__(self, *strategies: wait_base) -> None:
if not strategies:
raise ValueError("wait_chain() requires at least one strategy")
self.strategies = strategies

def __call__(self, retry_state: "RetryCallState") -> float:
Expand Down
11 changes: 7 additions & 4 deletions tests/test_tenacity.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,10 +541,13 @@ def always_return_1() -> int:
self.assertEqual(sleep_intervals, [1.0, 2.0, 3.0, 3.0])
sleep_intervals[:] = []

# Clear and restart retrying.
self.assertRaises(tenacity.RetryError, always_return_1)
self.assertEqual(sleep_intervals, [1.0, 2.0, 3.0, 3.0])
sleep_intervals[:] = []
def test_wait_chain_requires_at_least_one_strategy(self) -> None:
with self.assertRaises(ValueError):
tenacity.wait_chain()
# Confirm the wrapped Retrying path surfaces the same ValueError
# instead of an opaque IndexError from self.strategies[-1].
with self.assertRaises(ValueError):
Retrying(wait=tenacity.wait_chain())

def test_wait_random_exponential(self) -> None:
fn = tenacity.wait_random_exponential(0.5, 60.0)
Expand Down
Loading