Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix ANY method not appearing in the UrlDispatcher routes #9987

Merged
merged 5 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading