mirror of https://github.com/tiangolo/fastapi.git
Merge fc72f21b4b into 272204c0c7
This commit is contained in:
commit
c9d4deb223
|
|
@ -1388,6 +1388,10 @@ class APIRouter(routing.Router):
|
||||||
app.include_router(internal_router)
|
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:
|
if prefix:
|
||||||
assert prefix.startswith("/"), "A path prefix must start with '/'"
|
assert prefix.startswith("/"), "A path prefix must start with '/'"
|
||||||
assert not prefix.endswith("/"), (
|
assert not prefix.endswith("/"), (
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
import pytest
|
||||||
|
from fastapi import APIRouter
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_circular_import():
|
||||||
|
router = APIRouter()
|
||||||
|
|
||||||
|
with pytest.raises(
|
||||||
|
AssertionError,
|
||||||
|
match="Cannot include the same APIRouter instance into itself. Did you mean to include a different router?",
|
||||||
|
):
|
||||||
|
router.include_router(router)
|
||||||
Loading…
Reference in New Issue