Skip to content

wait_chain passes retry_state as keyword, breaking callable wait strategies #780

Description

@Omarinho12345

Describe the bug

wait_chain invokes the selected strategy with retry_state as a keyword argument, so any wait strategy that takes the state positionally under another parameter name raises TypeError. The same callable works with wait=, wait_fixed(0) + callable and wait_combine(wait_fixed(0), callable), which call it positionally.

To Reproduce

from tenacity import retry, stop_after_attempt
from tenacity.wait import wait_chain, wait_combine, wait_fixed

def my_wait(rs):
    return 0.0

@retry(stop=stop_after_attempt(2), wait=wait_chain(wait_fixed(0), my_wait),
       sleep=lambda s: None)
def f():
    raise ValueError

f()
TypeError: my_wait() got an unexpected keyword argument 'retry_state'
  tenacity/wait.py:135, in wait_chain.__call__

Replacing the wait with wait_combine(wait_fixed(0), my_wait) or wait_fixed(0) + my_wait retries normally.

Expected behavior

wait_chain should call strategies the way wait_combine does (positionally), so any WaitBaseT callable works regardless of its parameter name.

Environment

tenacity main at aac059c, Python 3.14.

Fix

Call the strategy positionally in wait_chain.__call__, widen its signature to WaitBaseT like wait_combine, and add a regression test.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions