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

Fix async generator handling #1844

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions connexion/decorators/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ async def wrapper(*args, **kwargs):
object.
"""
handler_response = await function(*args, **kwargs)
if isinstance(handler_response, t.Coroutine):
handler_response = await handler_response
if self.framework.is_framework_response(handler_response):
return handler_response
elif isinstance(handler_response, ConnexionResponse):
Expand Down
3 changes: 3 additions & 0 deletions connexion/frameworks/starlette.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import starlette.convertors
from starlette.responses import JSONResponse as StarletteJSONResponse
from starlette.responses import Response as StarletteResponse
from starlette.responses import StreamingResponse as StarletteStreamingResponse
from starlette.types import Receive, Scope

from connexion.frameworks.abstract import Framework
Expand Down Expand Up @@ -37,6 +38,8 @@ def build_response(
):
if isinstance(data, dict) or isinstance(data, list):
response_cls = StarletteJSONResponse
elif isinstance(data, t.Generator) or isinstance(data, t.AsyncGenerator):
response_cls = StarletteStreamingResponse
else:
response_cls = StarletteResponse

Expand Down
Loading