-
Notifications
You must be signed in to change notification settings - Fork 90
OpenAPI generator crashes with AttributeError on SSE async-generator handlers (AsyncIterable has no __parameters__) #674
Copy link
Copy link
Open
Description
name: "🐛 Bug Report"
about: "If something isn't working as expected."
title: ''
Description
When a controller method is defined as an async generator with the return type
-> AsyncIterable[ServerSentEvent] (as shown in the SSE documentation), the
OpenAPI documentation builder raises an AttributeError at startup and the
application fails to start.
Traceback
File ".../blacksheep/server/openapi/v3.py", line 1024, in _try_get_schema_for_generic
parameters = origin.__parameters__
^^^^^^^^^^^^^^^^^^^^^
AttributeError: type object 'AsyncIterable' has no attribute '__parameters__'
Minimal reproduction
from collections.abc import AsyncIterable
from blacksheep import Application, get
from blacksheep.server.sse import ServerSentEvent
from blacksheep.server.openapi.v3 import OpenApiHandler
from blacksheep.server.controllers import Controller
docs = OpenApiHandler(info=Info("Test", "0.1.0"))
app = Application()
docs.bind_app(app)
class Home(Controller):
@get("/events")
async def events(self) -> AsyncIterable[ServerSentEvent]:
yield ServerSentEvent({"msg": "hello"})Running this causes startup failure when the OpenAPI docs are generated.
Workaround
Use ServerSentEventsResponse with a plain (non-annotated) handler instead:
from blacksheep.server.sse import ServerSentEvent, ServerSentEventsResponse
class Home(Controller):
@get("/events")
def events(self):
async def generate():
yield ServerSentEvent({"msg": "hello"})
return ServerSentEventsResponse(generate)Expected behaviour
The OpenAPI generator should either handle AsyncIterable[ServerSentEvent] gracefully
(e.g. treat it as a streaming/SSE response and skip schema generation for it), or raise
a clear, actionable error message.
Environment
- BlackSheep version: 2.x
- Python version: 3.14
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels