Skip to content

Unsupported operand type(s) error #164

Closed
@iromli

Description

@iromli

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..

Activity

bgreen-litl

bgreen-litl commented on Jun 8, 2022

@bgreen-litl
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @iromli@bgreen-litl

        Issue actions

          Unsupported operand type(s) error · Issue #164 · litl/backoff