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

async singledispatch not retried #430

Open
thebuchanan3 opened this issue Jan 21, 2024 · 0 comments
Open

async singledispatch not retried #430

thebuchanan3 opened this issue Jan 21, 2024 · 0 comments

Comments

@thebuchanan3
Copy link

thebuchanan3 commented Jan 21, 2024

async functools.singledispatch or functools.singledispatchmethod decorated functions are not retried using tenacity:

import asyncio
import tenacity

from functools import singledispatch

@tenacity.retry(
    retry=tenacity.retry_if_exception_type(RuntimeError),
    stop=tenacity.stop_after_attempt(2),
)
@singledispatch
async def foo(a: str):
    raise RuntimeError()


asyncio.run(foo("test"))  # RuntimeError

The example is not retried and raises RuntimeError instead of tenacity.RetryError.

The reason is that inspect.iscoroutinefunction is used under the hood, which produces false negatives for singledispatch functions and methods.

from functools import singledispatch
from inspect import iscoroutinefunction

@singledispatch
async def foo(a: str):
    raise RuntimeError()


assert iscoroutinefunction(foo)  # AssertionError
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

1 participant