From a39d9c15164268c5a2a18c2a25223869da6cff4a Mon Sep 17 00:00:00 2001 From: Nilesh Patil <128893479+nileshpatil6@users.noreply.github.com> Date: Sat, 16 May 2026 20:22:42 +0530 Subject: [PATCH] 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. --- fastapi/routing.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fastapi/routing.py b/fastapi/routing.py index 21a1385a27..ddcdb53a3b 100644 --- a/fastapi/routing.py +++ b/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(