Skip to content

on_exception/on_predicate decators silently forward unknown params to wait_gen_kwargs — confusing TypeError #53

Description

@Llucs

Bug: condition/stop and other unknown params silently forwarded to wait_gen_kwargs in decorators

Severity: Medium
File: _decorator.py:370 (on_exception) and _decorator.py:62 (on_predicate)
Version: 4.2.4 (commit 0992494)

Description

The @on_exception and @on_predicate decorators accept **wait_gen_kwargs and pass them to _init_wait_gen, which forwards them to the wait generator. However, advanced parameters like condition, stop, and name that exist in Retrying and retry() are NOT in the decorator signatures. If a user passes them to a decorator, they go to **wait_gen_kwargs and then to the wait generator, causing a confusing TypeError:

TypeError: _Expo.__init__() got an unexpected keyword argument 'condition'

To Reproduce

import backon
from backon import retry_if_exception_message

cond = retry_if_exception_message("fail")

@backon.on_exception(backon.expo, ValueError, max_tries=3, condition=cond, jitter=None)
def fail():
    raise ValueError("fail")

Output:

TypeError: _Expo.__init__() got an unexpected keyword argument 'condition'

The error mentions _Expo instead of saying "condition is not a valid parameter for on_exception", which is misleading.

Suggested Fix

Either:

  1. Add condition and stop as explicit None parameters to the decorators (even if ignored) so they are consumed rather than forwarded
  2. Or add validation in _init_wait_gen to detect unexpected kwargs and provide a clear error message

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions