diff --git a/shared/sx/pages.py b/shared/sx/pages.py index f6654fc..855e588 100644 --- a/shared/sx/pages.py +++ b/shared/sx/pages.py @@ -520,10 +520,15 @@ def _mount_one_page(bp: Any, service_name: str, page_def: PageDef) -> None: if hasattr(result, "status_code"): return result return await make_response(result, 200) - # Streaming response — stream_with_context preserves app/request - # context across async generator yields - gen = execute_page_streaming(current, service_name, url_params=kwargs) - return Response(stream_with_context(gen), content_type="text/html; charset=utf-8") + # stream_with_context is a decorator — wrap the generator function + # so app/request context is preserved across yields + @stream_with_context + 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: # Standard non-streaming response async def page_view(**kwargs: Any) -> Any: