From b1a55e7875cad977e80704841e18b1f7706e05a0 Mon Sep 17 00:00:00 2001 From: svlyubovsk Date: Tue, 15 Oct 2024 20:53:50 +0300 Subject: [PATCH] fix: set correct path_template value for trie node --- litestar/_asgi/routing_trie/mapping.py | 3 ++- litestar/_asgi/routing_trie/traversal.py | 5 +++-- litestar/_asgi/routing_trie/types.py | 6 +++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/litestar/_asgi/routing_trie/mapping.py b/litestar/_asgi/routing_trie/mapping.py index 1a977d478d..c96db46cff 100644 --- a/litestar/_asgi/routing_trie/mapping.py +++ b/litestar/_asgi/routing_trie/mapping.py @@ -111,7 +111,7 @@ def add_route_to_trie( next_node_key = component if next_node_key not in current_node.children: - current_node.children[next_node_key] = create_node(path_template=route.path_format) + current_node.children[next_node_key] = create_node() current_node.child_keys = set(current_node.children.keys()) current_node = current_node.children[next_node_key] @@ -140,6 +140,7 @@ def configure_node( """ from litestar.routes import HTTPRoute, WebSocketRoute + node.path_template = route.path_format if not node.path_parameters: node.path_parameters = {} diff --git a/litestar/_asgi/routing_trie/traversal.py b/litestar/_asgi/routing_trie/traversal.py index 499e0e72a1..94b4eaeae8 100644 --- a/litestar/_asgi/routing_trie/traversal.py +++ b/litestar/_asgi/routing_trie/traversal.py @@ -133,8 +133,9 @@ 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 + node = root_node.children[path] + asgi_app, handler = parse_node_handlers(node=node, method=method) + return asgi_app, handler, path, {}, node.path_template if mount_paths_regex and (match := mount_paths_regex.match(path)): mount_path = path[: match.end()] diff --git a/litestar/_asgi/routing_trie/types.py b/litestar/_asgi/routing_trie/types.py index da86482dfa..a07e3d3567 100644 --- a/litestar/_asgi/routing_trie/types.py +++ b/litestar/_asgi/routing_trie/types.py @@ -34,9 +34,9 @@ class RouteTrieNode: "children", "is_asgi", "is_mount", - "is_static", "is_path_param_node", "is_path_type", + "is_static", "path_parameters", "path_template", ) @@ -68,7 +68,7 @@ class RouteTrieNode: """The path template string used to lower prometheus cardinality when group_path enabled""" -def create_node(path_template: str = "") -> RouteTrieNode: +def create_node() -> RouteTrieNode: """Create a RouteMapNode instance. Returns: @@ -85,5 +85,5 @@ def create_node(path_template: str = "") -> RouteTrieNode: is_static=False, is_path_type=False, path_parameters={}, - path_template=path_template, + path_template="", )