Browse Source

fix: propagate stream_item_type when using include_router

Fixes #15401: SSE stream_item_type was not copied from source routes to
merged routes when using APIRouter + include_router. The stream detection
branch in APIRoute.__init__ only runs when response_model is a
DefaultPlaceholder. After include_router copies route.response_model (which
is already None), the branch is skipped and stream_item_type stays None.

Now explicitly copy stream_item_type and stream_item_field from source route
to the merged route after add_api_route creates it.
pull/15544/head
Nilesh Patil 2 months ago
parent
commit
a39d9c1516
  1. 5
      fastapi/routing.py

5
fastapi/routing.py

@ -1794,6 +1794,11 @@ class APIRouter(routing.Router):
self.strict_content_type,
),
)
if route.stream_item_type is not None:
new_route = self.routes[-1]
assert isinstance(new_route, APIRoute)
new_route.stream_item_type = route.stream_item_type
new_route.stream_item_field = route.stream_item_field
elif isinstance(route, routing.Route):
methods = list(route.methods or [])
self.add_route(

Loading…
Cancel
Save