Browse Source

Merge branch 'master' into fix-path-converter-path-params

pull/14883/head
Dawit Worku 5 months ago
committed by GitHub
parent
commit
9cc0b276ef
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 5
      docs/en/docs/release-notes.md
  2. 4
      fastapi/exceptions.py
  3. 4
      fastapi/routing.py
  4. 12
      tests/test_router_circular_import.py

5
docs/en/docs/release-notes.md

@ -7,6 +7,11 @@ hide:
## Latest Changes ## Latest Changes
### Features
* ✨ Show a clear error on attempt to include router into itself. PR [#14258](https://github.com/fastapi/fastapi/pull/14258) by [@JavierSanchezCastro](https://github.com/JavierSanchezCastro).
* ✨ Replace `dict` by `Mapping` on `HTTPException.headers`. PR [#12997](https://github.com/fastapi/fastapi/pull/12997) by [@rijenkii](https://github.com/rijenkii).
### Internal ### Internal
* 🔧 Configure `test` workflow to run tests with `inline-snapshot=review`. PR [#14876](https://github.com/fastapi/fastapi/pull/14876) by [@YuriiMotov](https://github.com/YuriiMotov). * 🔧 Configure `test` workflow to run tests with `inline-snapshot=review`. PR [#14876](https://github.com/fastapi/fastapi/pull/14876) by [@YuriiMotov](https://github.com/YuriiMotov).

4
fastapi/exceptions.py

@ -1,4 +1,4 @@
from collections.abc import Sequence from collections.abc import Mapping, Sequence
from typing import Annotated, Any, Optional, TypedDict, Union from typing import Annotated, Any, Optional, TypedDict, Union
from annotated_doc import Doc from annotated_doc import Doc
@ -68,7 +68,7 @@ class HTTPException(StarletteHTTPException):
), ),
] = None, ] = None,
headers: Annotated[ headers: Annotated[
Optional[dict[str, str]], Optional[Mapping[str, str]],
Doc( Doc(
""" """
Any headers to send to the client in the response. Any headers to send to the client in the response.

4
fastapi/routing.py

@ -1393,6 +1393,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("/"), (

12
tests/test_router_circular_import.py

@ -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…
Cancel
Save