Skip to content

fix: call wait_chain members positionally - #699

Open
codechrl wants to merge 1 commit into
jd:mainfrom
codechrl:fix-wait-chain-positional
Open

fix: call wait_chain members positionally#699
codechrl wants to merge 1 commit into
jd:mainfrom
codechrl:fix-wait-chain-positional

Conversation

@codechrl

Copy link
Copy Markdown

wait_chain.__call__ calls each member strategy as
wait_func(retry_state=retry_state). WaitBaseT is
Callable[[RetryCallState], float | int], so a plain callable takes the
state positionally and need not name its parameter retry_state. Such a
member raises TypeError: <lambda>() got an unexpected keyword argument 'retry_state'.

The effect is that a plain callable cannot be used inside a wait_chain,
which is the combinator for phase-based backoff. The same callable works as
wait=, because BaseRetrying._run_wait calls it positionally. The failure
needs both a wait_chain and an attempt that retries, so it surfaces at the
first retry rather than at construction.

The fix passes the state positionally and widens wait_chain(*strategies)
from wait_base to WaitBaseT. #694 made both changes for wait_combine.
tenacity/asyncio does not override wait_chain.

A/B verified against 26f719d: test_wait_chain_passes_state_positionally
fails with the TypeError above before the change and passes after.
Reverting the tenacity/wait.py hunk alone puts it back to failing. Release
note added under releasenotes/notes/.

wait_chain.__call__ calls each member strategy as
wait_func(retry_state=retry_state). WaitBaseT admits plain callables,
which accept the state positionally without naming the parameter
retry_state. Such a member raises TypeError on the first retry. The same
callable works as wait=, because _run_wait calls it positionally.

jd#694 fixed the same call convention in wait_combine and widened
wait_combine.__init__ to WaitBaseT.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant