Skip to content

Commit

Permalink
Fix ANY method not appearing in the UrlDispatcher routes (#9987)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Nov 19, 2024
1 parent 4c3b1c6 commit 7199e09
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 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 @@ -356,9 +356,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
6 changes: 6 additions & 0 deletions tests/test_urldispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,12 @@ async def test_any_method(router: web.UrlDispatcher) -> None:
assert info1.route is info2.route


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()
Expand Down

0 comments on commit 7199e09

Please sign in to comment.