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

8.4.2 breaks suggested way to overwrite tenacity behaviors on unit tests #482

Closed
thiagogodoi opened this issue Jun 25, 2024 · 7 comments · Fixed by #484
Closed

8.4.2 breaks suggested way to overwrite tenacity behaviors on unit tests #482

thiagogodoi opened this issue Jun 25, 2024 · 7 comments · Fixed by #484

Comments

@thiagogodoi
Copy link

Looks like the change introduced with 8.4.2: 8.4.1...8.4.2

Breaks the suggested behavior to overwrite tenacity wait time/retry confiig on tests, as suggested here:

#106

Doesn't looks like this was done by propose, is it expected? If yes, what would be the suggested way to ovewrite the retry config in tests to speed it up?

@vinayan3
Copy link

I'm also seeing this too because the removal of this has thrown off everything

wrapped_f.retry = self # type: ignore[attr-defined]

There is no way to access the retry object now.

@jd
Copy link
Owner

jd commented Jun 26, 2024

cc @hasier

@DaveFelce
Copy link

Also seeing this after upgrade to 8.4.2. Things like this used to work, but no longer - the test suite which used to take 2 mins to run now takes 12:

external_api_call.retry.stop = stop_after_attempt(1)

@anlambert
Copy link

anlambert commented Jun 28, 2024

I also got hit by that regression, it seems simply mocking time.sleep is enough now to avoid waiting when testing. It did not resolve the issue of having access to the retry object though.

@robfraz
Copy link

robfraz commented Jul 2, 2024

Am also hit by this regression. Using an earlier version for tenacity for now.

@hasier
Copy link
Contributor

hasier commented Jul 4, 2024

@jd this use case seems like one more iteration on the fix for the initial scenario #478. I changed the value for .retry as we need to account for recursive calls to the retriable function. If the value is not copied and therefore shared, then the recursive calls would end up overwriting instance values which affect the operations higher up the stack (this is already a problem with .statistics as well, as they are currently overwritten for the whole function...).

The root cause to me feels like the need to read properties for a decorated function while accounting for the fact that it can be called recursively, in which case the wrapping retry object, statistics, etc. lose a bit of meaning. If we were to tackle this more generally, maybe we'd need to separately track the calls and retry objects in a sort-of-list format, so that each call and their properties can be checked separately? In this case we could keep a writeable retry object for the purpose of this issue, but its read values should not be used (e.g. statistics), we should refer to the new tracking list.

If you prefer a more short-term solution, I feel like there are a couple of different things we could do, depending on your preference:

  • Restore the value of retry. This means we need to change the tests (and docs/assumptions) for TestDecoratorWrapper and TestStatistics, as retry should only be accessed to modify the retry object, but not to read its properties, e.g. statistics should be read directly from the function (instead of doing this, I feel maybe we'd be better off tackling the above recursive scenario instead as a more general fix).
  • Keep the current value. We'd assume retry is just a special value to call the function (not too sure this is very valuable) and mocks need to be applied differently.

@jd
Copy link
Owner

jd commented Jul 4, 2024

I feel like restoring the assignment to self and make it clear that the object access is only meant to read/modify the retry object is the way to go.

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

Successfully merging a pull request may close this issue.

7 participants