wait_chain: reject empty strategy list with ValueError instead of IndexError#647
Merged
mergify[bot] merged 1 commit intoJul 3, 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 3, 2026
Contributor
Merge Queue Status
This pull request spent 16 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 wait strategies and stores them inself.strategies. When called with no strategies,self.strategiesends up as(). The first call to__call__then evaluatesmin(max(1, 1), 0) == 0, soself.strategies[wait_func_no - 1]turns intoself.strategies[-1]and raises anIndexErrorfrom inside a running retry.This is opaque for what is really a programmer error at construction time. An empty
wait_chainhas no useful behaviour, so failing early is friendlier than letting it crash later from amin(max(1, 1), 0)corner case.Fix
tenacity/wait.py: validate in__init__and raiseValueError('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.Tests
tests/test_tenacity.py:test_wait_chain_requires_at_least_one_strategy— assertsValueErrorfrom the barewait_chain()constructor and from the wrappedRetrying(wait=wait_chain())path that previously surfaced theIndexError.The change is one validation line plus the test. A release note is included in
releasenotes/notes/.