wait_chain: reject empty strategy list with ValueError instead of IndexError#646
Merged
mergify[bot] merged 1 commit intoJul 1, 2026
Merged
Conversation
…exError
Calling wait_chain() with no strategies stored an empty tuple in
self.strategies. The first call to __call__ then evaluated
min(max(1, 1), 0) == 0, so self.strategies[wait_func_no - 1]
turned into self.strategies[-1] and raised IndexError, which is
opaque for what is really a programmer error at construction time.
Validate in __init__ and raise ValueError('wait_chain() requires
at least one strategy') so the failure happens at the point where
the bad configuration is created, not later when the wait function
is first evaluated inside a running retry.
jd
approved these changes
Jul 1, 2026
Contributor
Merge Queue Status
This pull request spent 10 seconds in the queue, including 2 seconds running CI. Required conditions to merge |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
wait_chain()accepts a variadic list of strategies, but did not validate that the list is non-empty. The bad configuration only surfaced at the first call site of the resulting wait function, whereself.strategies[-1]raisedIndexError: tuple index out of range. This is confusing because the programmer error is at construction time, not at the moment the wait function is invoked inside a running retry.This change makes
wait_chain()raise a clearValueError("wait_chain() requires at least one strategy")at construction time.Repro of the pre-fix behaviour
With the patch, the same sequence raises
ValueErroron thewait_chain()call itself.Changes
tenacity/wait.py:wait_chain.__init__now raisesValueErrorwhen*strategiesis empty.tests/test_tenacity.py: addedtest_wait_chain_requires_at_least_one_strategy, which coverswait_chain()directly,Retrying(... wait=wait_chain())at construction, and confirms a non-empty chain still works.releasenotes/notes/fix-wait-chain-empty-strategies-...yaml: short user-facing note.Tests
AssertionError: ValueError not raised) and passes on the patched code.tests/test_tenacity.pyrun: 128 passed.ruff check: clean.ruff format --check: clean.