Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unsupported operand type(s) error #164

Closed
iromli opened this issue Jun 7, 2022 · 1 comment
Closed

Unsupported operand type(s) error #164

iromli opened this issue Jun 7, 2022 · 1 comment

Comments

@iromli
Copy link

iromli commented Jun 7, 2022

I'm trying to upgrade backoff from v1.11.x to v2.1.0 but blocked by an error when passing callable to max_time argument, as seen in the example below:

import backoff


def lookup_max_time():
    return 30


@backoff.on_exception(
    backoff.constant,
    ValueError,
    max_time=lookup_max_time,
)
def wait_for(*args, **kwargs):
    raise ValueError("err")


if __name__ == "__main__":
    wait_for()

Here's the traceback:

Traceback (most recent call last):
  File "/home/iromli/contrib/backoff/backoff/_sync.py", line 104, in retry
    ret = target(*args, **kwargs)
  File "/home/iromli/contrib/backoff/dist/testing_backoff.py", line 14, in wait_for
    raise ValueError("err")
ValueError: err

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/iromli/contrib/backoff/dist/testing_backoff.py", line 18, in <module>
    wait_for()
  File "/home/iromli/contrib/backoff/backoff/_sync.py", line 117, in retry
    seconds = _next_wait(wait, e, jitter, elapsed, max_time)
  File "/home/iromli/contrib/backoff/backoff/_common.py", line 54, in _next_wait
    seconds = min(seconds, max_time - elapsed)
TypeError: unsupported operand type(s) for -: 'function' and 'float'

It seems that when calling _next_wait function, the max_time value is the callable instead of the actual value returned by callable.

Thanks..

@bgreen-litl
Copy link
Member

Thank you. This is now fixed and released in backoff 2.1.1

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

No branches or pull requests

2 participants