← baseline_full_v2

fastapi_14301

failed NO_PATCH NO_PATCH UNSUBMITTED empty_patch(None) · None tool calls · 0 s · fastapi/fastapi

Task input

🐛 Fix `Depends(func, scope='function')` for top level (parameterless) dependencies

**Summary**

This PR enables proper support for `scope="function"` on `APIRoute` dependencies by passing the dependency’s scope through to `get_dependant`. Previously, parameter-less dependencies created via `get_parameterless_sub_dependant` ignored `depends.scope`, which led to unexpected behavior for function-scoped dependencies.

**Motivation**

Users expect `scope="function"` to work as defined, even when registered at the route level. Because `depends.scope` wasn’t forwarded, function scope behaved like the default(request). This change aligns behavior with user expectations and documentation around dependency scopes.
(Related: #14296)

Tool calls (0)

#ToolArgumentsResult
No trace captured.

Test output

show
uth
    response = self._send_handling_redirects(
/Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/fastapi/lib/python3.13/site-packages/httpx/_client.py:979: in _send_handling_redirects
    response = self._send_single_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/fastapi/lib/python3.13/site-packages/httpx/_client.py:1014: in _send_single_request
    response = transport.handle_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/overlays/starlette-0.49.3-py3-none-any/starlette/testclient.py:354: in handle_request
    raise exc
/Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/overlays/starlette-0.49.3-py3-none-any/starlette/testclient.py:351: in handle_request
    portal.call(self.app, scope, receive, send)
/Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/fastapi/lib/python3.13/site-packages/anyio/from_thread.py:340: in call
    return cast(T_Retval, self.start_task_soon(func, *args).result())
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/Users/jp/.local/share/uv/python/cpython-3.13.15-macos-aarch64-none/lib/python3.13/concurrent/futures/_base.py:460: in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
/Users/jp/.local/share/uv/python/cpython-3.13.15-macos-aarch64-none/lib/python3.13/concurrent/futures/_base.py:402: in __get_result
    raise self._exception
/Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/fastapi/lib/python3.13/site-packages/anyio/from_thread.py:265: in _call_func
    retval = await retval_or_awaitable
             ^^^^^^^^^^^^^^^^^^^^^^^^^
fastapi/applications.py:1134: in __call__
    await super().__call__(scope, receive, send)
/Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/overlays/starlette-0.49.3-py3-none-any/starlette/applications.py:113: in __call__
    await self.middleware_stack(scope, receive, send)
/Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/overlays/starlette-0.49.3-py3-none-any/starlette/middleware/errors.py:186: in __call__
    raise exc
/Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/overlays/starlette-0.49.3-py3-none-any/starlette/middleware/errors.py:164: in __call__
    await self.app(scope, receive, _send)
/Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/overlays/starlette-0.49.3-py3-none-any/starlette/middleware/exceptions.py:63: in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
/Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/overlays/starlette-0.49.3-py3-none-any/starlette/_exception_handler.py:53: in wrapped_app
    raise exc
/Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/overlays/starlette-0.49.3-py3-none-any/starlette/_exception_handler.py:42: in wrapped_app
    await app(scope, receive, sender)
fastapi/middleware/asyncexitstack.py:18: in __call__
    await self.app(scope, receive, send)
/Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/overlays/starlette-0.49.3-py3-none-any/starlette/routing.py:716: in __call__
    await self.middleware_stack(scope, receive, send)
/Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/overlays/starlette-0.49.3-py3-none-any/starlette/routing.py:736: in app
    await route.handle(scope, receive, send)
/Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/overlays/starlette-0.49.3-py3-none-any/starlette/routing.py:290: in handle
    await self.app(scope, receive, send)
fastapi/routing.py:125: in app
    await wrap_app_handling_exceptions(app, request)(scope, receive, send)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

scope = {'type': 'http', 'http_version': '1.1', 'method': 'GET', 'path': '/router-scope-function/', ...}
receive = <function _TestClientTransport.handle_request.<locals>.receive at 0x107b35b20>
send = <function wrap_app_handling_exceptions.<locals>.wrapped_app.<locals>.sender at 0x11000f060>

    async def wrapped_app(scope: Scope, receive: Receive, send: Send) -> None:
        response_started = False
    
        async def sender(message: Message) -> None:
            nonlocal response_started
    
            if message["type"] == "http.response.start":
                response_started = True
            await send(message)
    
        try:
            await app(scope, receive, sender)
        except Exception as exc:
            handler = None
    
            if isinstance(exc, HTTPException):
                handler = status_handlers.get(exc.status_code)
    
            if handler is None:
                handler = _lookup_exception_handler(exception_handlers, exc)
    
            if handler is None:
                raise exc
    
            if response_started:
>               raise RuntimeError("Caught handled exception, but response already started.") from exc
E               RuntimeError: Caught handled exception, but response already started.

/Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/overlays/starlette-0.49.3-py3-none-any/starlette/_exception_handler.py:56: RuntimeError
=============================== warnings summary ===============================
../../../../../../../Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/overlays/starlette-0.49.3-py3-none-any/starlette/testclient.py:51
  /Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/overlays/starlette-0.49.3-py3-none-any/starlette/testclient.py:51: DeprecationWarning: The anyio.abc.BlockingPortal alias is deprecated, use anyio.from_thread.BlockingPortal instead.
    _PortalFactoryType = Callable[[], AbstractContextManager[anyio.abc.BlockingPortal]]

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!
1 failed, 7 passed, 1 warning in 0.79s