File tree Expand file tree Collapse file tree 1 file changed +22
-10
lines changed
Expand file tree Collapse file tree 1 file changed +22
-10
lines changed Original file line number Diff line number Diff line change @@ -76,16 +76,6 @@ async def get_function_dependencies(
7676 # Synthesize defaults
7777 if not url :
7878 url = "/synthetic"
79- if not request :
80- request = Request (
81- scope = {
82- "type" : "http" ,
83- "path" : url ,
84- "path_params" : {},
85- "query_string" : "" ,
86- "headers" : [],
87- }
88- )
8979
9080 # Synthetic request object as if we're coming from the original first page
9181 dependant = get_dependant (
@@ -94,6 +84,28 @@ async def get_function_dependencies(
9484 )
9585
9686 async with AsyncExitStack () as async_exit_stack :
87+ # FastAPI 0.118+ requires these exit stacks in the request scope for
88+ # dependency resolution. We provide them for backwards compatibility.
89+ if not request :
90+ request = Request (
91+ scope = {
92+ "type" : "http" ,
93+ "path" : url ,
94+ "path_params" : {},
95+ "query_string" : "" ,
96+ "headers" : [],
97+ # FastAPI 0.118+ scope requirements
98+ "fastapi_inner_astack" : async_exit_stack ,
99+ "fastapi_function_astack" : async_exit_stack ,
100+ }
101+ )
102+ else :
103+ # Inject into existing request scope if not present
104+ if "fastapi_inner_astack" not in request .scope :
105+ request .scope ["fastapi_inner_astack" ] = async_exit_stack
106+ if "fastapi_function_astack" not in request .scope :
107+ request .scope ["fastapi_function_astack" ] = async_exit_stack
108+
97109 payload = await solve_dependencies (
98110 request = request ,
99111 dependant = dependant ,
You can’t perform that action at this time.
0 commit comments