← oracle_full

fastapi_14258

resolved RESOLVED UNSUBMITTED PASS · None tool calls · 0 s · fastapi/fastapi

Task input

✨ Show a clear error on attempt to include router into itself

Previously discussed in https://github.com/fastapi/fastapi/discussions/11424 with the PR at https://github.com/fastapi/fastapi/pull/11425

Since I made modifications in the fork of the repo, the PR was automatically closed. This PR serves to add the circular reference check again. Discussed again in https://github.com/fastapi/fastapi/discussions/14251

Tool calls (0)

#ToolArgumentsResult
No trace captured.

Patch

--- a/fastapi/routing.py
+++ b/fastapi/routing.py
@@ -1393,6 +1393,10 @@ def read_users():
         app.include_router(internal_router)
         ```
         """
+        assert self is not router, (
+            "Cannot include the same APIRouter instance into itself. "
+            "Did you mean to include a different router?"
+        )
         if prefix:
             assert prefix.startswith("/"), "A path prefix must start with '/'"
             assert not prefix.endswith("/"), (

Test output

show
.                                                                        [100%]
1 passed in 0.29s