resolved RESOLVED UNSUBMITTED PASS · None tool calls · 0 s · fastapi/fastapi
✨ 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 | Arguments | Result |
|---|---|---|---|
| No trace captured. | |||
--- 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("/"), (. [100%] 1 passed in 0.29s