Respect enabled=False on the direct-call path#645
Open
greymoth-jp wants to merge 2 commits into
Open
Conversation
`Retrying.__call__` and `AsyncRetrying.__call__` ignored the `enabled` flag: calling a controller created with `enabled=False` still ran the full retry loop, so a failing function was retried and the original exception was wrapped in a `RetryError`. This makes the direct-call protocol consistent with the decorator (`@retry(enabled=False)`) and the iterator protocols (`__iter__`/`__aiter__`, fixed in jd#643): with `enabled=False` the function is executed exactly once and any exception propagates unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Retrying(enabled=False)(fn)andAsyncRetrying(enabled=False)(fn)ignoreenabled=Falseon the direct-call path — they run the full retry loop and wrap the original exception inRetryError, instead of calling the function once and propagating its exception.PR #643 added the
enabled=Falseshort-circuit to the iterator protocols (__iter__/__aiter__/__anext__) but the direct-call protocol (__call__) was left behind, sinceiter()itself never consultsenabled. The fix adds the same short-circuit at the top of each__call__(awaiting coroutine callables for the async path).Verified both ways: old runs the function 5× and raises
RetryError(sync and async); fixed calls once and raises the originalValueError, matching the iterator/decorator paths. 154 existing tests green; +4 regression tests (which fail on the unfixed code) → 158 passed.