diff --git a/CHANGES/9899.bugfix.rst b/CHANGES/9899.bugfix.rst new file mode 120000 index 00000000000..e27324697dc --- /dev/null +++ b/CHANGES/9899.bugfix.rst @@ -0,0 +1 @@ +9987.bugfix.rst \ No newline at end of file diff --git a/CHANGES/9987.bugfix.rst b/CHANGES/9987.bugfix.rst new file mode 100644 index 00000000000..c2f172ac612 --- /dev/null +++ b/CHANGES/9987.bugfix.rst @@ -0,0 +1 @@ +Fixed the ``ANY`` method not appearing in :meth:`~aiohttp.web.UrlDispatcher.routes` -- by :user:`bdraco`. diff --git a/aiohttp/web_urldispatcher.py b/aiohttp/web_urldispatcher.py index b6e401975f3..e16f973984c 100644 --- a/aiohttp/web_urldispatcher.py +++ b/aiohttp/web_urldispatcher.py @@ -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: diff --git a/tests/test_urldispatch.py b/tests/test_urldispatch.py index 0f3fc62fdda..61bd415f562 100644 --- a/tests/test_urldispatch.py +++ b/tests/test_urldispatch.py @@ -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()