Skip to content

Commit

Permalink
[PR #9987/7199e09 backport][3.12] Fix ANY method not appearing in…
Browse files Browse the repository at this point in the history
… the ``UrlDispatcher`` routes (#9989)
  • Loading branch information
bdraco authored Nov 19, 2024
1 parent 79f2a94 commit 6d192e7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES/9899.bugfix.rst
1 change: 1 addition & 0 deletions CHANGES/9987.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed the ``ANY`` method not appearing in :meth:`~aiohttp.web.UrlDispatcher.routes` -- by :user:`bdraco`.
5 changes: 2 additions & 3 deletions aiohttp/web_urldispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,8 @@ def register_route(self, route: "ResourceRoute") -> None:
), f"Instance of Route class is required, got {route!r}"
if route.method == hdrs.METH_ANY:
self._any_route = route
else:
self._allowed_methods.add(route.method)
self._routes[route.method] = route
self._allowed_methods.add(route.method)
self._routes[route.method] = route

async def resolve(self, request: Request) -> _Resolve:
if (match_dict := self._match(request.rel_url.path_safe)) is None:
Expand Down
8 changes: 7 additions & 1 deletion tests/test_urldispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,13 @@ async def test_any_method(router) -> None:
assert info1.route is info2.route


async def test_match_second_result_in_table(router) -> None:
async def test_any_method_appears_in_routes(router: web.UrlDispatcher) -> None:
handler = make_handler()
route = router.add_route(hdrs.METH_ANY, "/", handler)
assert route in router.routes()


async def test_match_second_result_in_table(router: web.UrlDispatcher) -> None:
handler1 = make_handler()
handler2 = make_handler()
router.add_route("GET", "/h1", handler1)
Expand Down

0 comments on commit 6d192e7

Please sign in to comment.