Fix stream_with_context usage: it's a decorator, not a wrapper
stream_with_context decorates a generator function, not a generator instance. Wrap execute_page_streaming in a decorated inner function. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -520,10 +520,15 @@ def _mount_one_page(bp: Any, service_name: str, page_def: PageDef) -> None:
|
|||||||
if hasattr(result, "status_code"):
|
if hasattr(result, "status_code"):
|
||||||
return result
|
return result
|
||||||
return await make_response(result, 200)
|
return await make_response(result, 200)
|
||||||
# Streaming response — stream_with_context preserves app/request
|
# stream_with_context is a decorator — wrap the generator function
|
||||||
# context across async generator yields
|
# so app/request context is preserved across yields
|
||||||
gen = execute_page_streaming(current, service_name, url_params=kwargs)
|
@stream_with_context
|
||||||
return Response(stream_with_context(gen), content_type="text/html; charset=utf-8")
|
async def _stream():
|
||||||
|
async for chunk in execute_page_streaming(
|
||||||
|
current, service_name, url_params=kwargs,
|
||||||
|
):
|
||||||
|
yield chunk
|
||||||
|
return Response(_stream(), content_type="text/html; charset=utf-8")
|
||||||
else:
|
else:
|
||||||
# Standard non-streaming response
|
# Standard non-streaming response
|
||||||
async def page_view(**kwargs: Any) -> Any:
|
async def page_view(**kwargs: Any) -> Any:
|
||||||
|
|||||||
Reference in New Issue
Block a user