From fd3ff421dabbad266b4f85f5e0334121ea7a0e86 Mon Sep 17 00:00:00 2001 From: Mohammed Babelly Date: Sat, 19 Oct 2024 12:55:06 +0400 Subject: [PATCH] fix(prometheus): fix path template for routes without path parameters (#3784) --- litestar/_asgi/routing_trie/traversal.py | 2 +- .../prometheus/test_prometheus_exporter_example.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/litestar/_asgi/routing_trie/traversal.py b/litestar/_asgi/routing_trie/traversal.py index 499e0e72a1..77d1b4b3d3 100644 --- a/litestar/_asgi/routing_trie/traversal.py +++ b/litestar/_asgi/routing_trie/traversal.py @@ -134,7 +134,7 @@ def parse_path_to_route( try: if path in plain_routes: asgi_app, handler = parse_node_handlers(node=root_node.children[path], method=method) - return asgi_app, handler, path, {}, root_node.path_template + return asgi_app, handler, path, {}, path if mount_paths_regex and (match := mount_paths_regex.match(path)): mount_path = path[: match.end()] diff --git a/tests/examples/test_contrib/prometheus/test_prometheus_exporter_example.py b/tests/examples/test_contrib/prometheus/test_prometheus_exporter_example.py index 7a45636e76..5ea31042c0 100644 --- a/tests/examples/test_contrib/prometheus/test_prometheus_exporter_example.py +++ b/tests/examples/test_contrib/prometheus/test_prometheus_exporter_example.py @@ -20,7 +20,8 @@ def clear_collectors() -> None: @pytest.mark.parametrize( "group_path, route_path, route_template, expected_path", [ - (True, "/test/litestar", "test/{name:str}", "/test/{name}"), + (True, "/test/litestar", "test/litestar", "/test/litestar"), + (False, "/test/litestar", "test/litestar", "/test/litestar"), (True, "/test/litestar", "test/{name:str}", "/test/{name}"), (False, "/test/litestar", "test/{name:str}", "/test/litestar"), (