Giter Club home page Giter Club logo

Comments (6)

vijaysitaram avatar vijaysitaram commented on August 20, 2024

Seeing something similar. Sanitized sample of our code:

    @tenacity.retry(
        retry=tenacity.retry_if_exception_type(MyCustomError),
        stop=tenacity.stop_after_attempt(MAX_ATTEMPTS),
    )
    def _internal():
        attempt_number = _internal.retry.statistics["attempt_number"]
        ...

now gives this during execution

KeyError: 'attempt_number'

from tenacity.

jd avatar jd commented on August 20, 2024

@hasier is this something we could avoid breaking or should I just bump to version 9?

from tenacity.

hasier avatar hasier commented on August 20, 2024

I'd say it's difficult to keep that API, as per #484 we need a new retry instance each time the function is called to avoid overwriting the retry context on recursive calls, so that retry object cannot be used for statistics anymore. Unless y'all can think of a different approach, maybe this does deserve a major version bump. Sorry about that.

from tenacity.

g3n35i5 avatar g3n35i5 commented on August 20, 2024

@hasier no worries, this can happen :)

I'm totally fine with the API change, but as you said this should be a major version bump.

from tenacity.

vijaysitaram avatar vijaysitaram commented on August 20, 2024

@hasier same, gotta do what you gotta do. We ended up working around it in our code by using the previous implementation if it exists or falling back to the newer one, e.g. from
attempt_number = _internal.retry.statistics["attempt_number"]
to
attempt_number = _internal.retry.statistics.get("attempt_number") or _internal.statistics.get("attempt_number")

from tenacity.

steve-marmalade avatar steve-marmalade commented on August 20, 2024

@vijaysitaram thanks for the one-liner; this helped us quickly patch our application code.

I agree with others that this should be a major version bump; we just got hit with the same error (and it hits a rare enough code path that we didn't catch it in staging).

from tenacity.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.