Skip to content

fix _run_authentication creating the coroutine result twice #1457

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

eugenenelou
Copy link
Contributor

This fix a problem where _run_authentication in sync mode and async callback instantiate the coroutine twice and awaits the second one.

This raises a "coroutine not awaited" warning, which is annoying.

Comment on lines 207 to 216
if is_async_callable(callback) or getattr(callback, "is_async", False):
result = callback(request)
if inspect.iscoroutine(result):
result = async_to_sync(callback)(request)

async def await_result(cor: Coroutine) -> Any:
return await cor

result = async_to_sync(await_result)(result)
else:
result = callback(request)
Copy link

@matez0 matez0 May 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the try block,

                result = callback(request)
                if inspect.iscoroutine(result):
                    async def await_result(cor: Coroutine) -> Any:
                        return await cor

                    result = async_to_sync(await_result)(result)

would not be enough since result is created the same way in all cases and we may want to await result independently of the properties of callback?

@vitalik
Copy link
Owner

vitalik commented May 6, 2025

@eugenenelou could you show example code(authenticator?) that triggers "coroutine not awaited" warning ?

Ideally include it tests

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 this pull request may close these issues.

3 participants