From 3ca6799377761a83c9facb9e38474902a0b98b29 Mon Sep 17 00:00:00 2001 From: HardMax71 Date: Fri, 25 Sep 2026 16:40:07 +0200 Subject: [PATCH] fix(abstractions): give each RequestInformation its own path_parameters dict path_parameters defaulted to a dict literal that every RequestInformation created without one shared, so a path parameter set on one request reached the others and the url setter's clear() emptied them all. It now defaults to None and a new dict; a dict that is passed in is used as is. Fixes #753. --- .../kiota_abstractions/request_information.py | 8 ++-- .../tests/test_request_information.py | 39 ++++++++++++++++++- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/packages/abstractions/kiota_abstractions/request_information.py b/packages/abstractions/kiota_abstractions/request_information.py index d4e1518b..9538f177 100644 --- a/packages/abstractions/kiota_abstractions/request_information.py +++ b/packages/abstractions/kiota_abstractions/request_information.py @@ -48,7 +48,7 @@ def __init__( self, method: Optional[Method] = None, url_template: Optional[str] = None, - path_parameters: dict[str, Any] = {} + path_parameters: Optional[dict[str, Any]] = None ) -> None: """Creates a new instance of the RequestInformation class. @@ -56,15 +56,15 @@ def __init__( method (Method): The request method. url_template (str): The given url template. path_parameters (dict[str, Any], optional): Path parameters - for the request. Defaults to {}. + for the request. Defaults to a new empty dict. """ # The uri of the request self.__uri: Optional[Url] = None self.__request_options: dict[str, RequestOption] = {} - # The path parameters for the current request - self.path_parameters: dict[str, Any] = path_parameters + # The path parameters for the current request, a new dict unless the caller passes one + self.path_parameters: dict[str, Any] = {} if path_parameters is None else path_parameters # The URL template for the request self.url_template: Optional[str] = url_template diff --git a/packages/abstractions/tests/test_request_information.py b/packages/abstractions/tests/test_request_information.py index 9cf3711a..4b2b782f 100644 --- a/packages/abstractions/tests/test_request_information.py +++ b/packages/abstractions/tests/test_request_information.py @@ -226,4 +226,41 @@ def test_sets_time_only_values_in_path_parameters(): assert request_info.url == "https://example.com/daysFrom/00%3A20%3A00" - \ No newline at end of file + + +def test_each_request_information_gets_its_own_path_parameters(): + first = RequestInformation(Method.GET, "{+baseurl}/users/{user%2Did}/messages") + second = RequestInformation(Method.GET, "{+baseurl}/users/{user%2Did}/calendar") + + first.path_parameters["user%2Did"] = "alice" + + assert first.path_parameters is not second.path_parameters + assert "user%2Did" not in second.path_parameters + + +def test_a_path_parameter_set_on_one_request_does_not_reach_another_url(): + first = RequestInformation(Method.GET, "{+baseurl}/users/{user%2Did}/messages") + first.path_parameters.update({"baseurl": "https://graph.microsoft.com/v1.0", "user%2Did": "alice"}) + second = RequestInformation(Method.GET, "{+baseurl}/me/calendar") + second.path_parameters["baseurl"] = "https://graph.microsoft.com/v1.0" + + assert first.url == "https://graph.microsoft.com/v1.0/users/alice/messages" + assert second.path_parameters == {"baseurl": "https://graph.microsoft.com/v1.0"} + + +def test_passed_path_parameters_are_used_as_given(): + path_parameters = {"baseurl": "https://graph.microsoft.com/v1.0"} + + request_info = RequestInformation(Method.GET, "{+baseurl}/me", path_parameters) + + assert request_info.path_parameters is path_parameters + + +def test_setting_a_raw_url_does_not_clear_another_requests_path_parameters(): + templated = RequestInformation(Method.GET, "{+baseurl}/users/{user%2Did}/messages") + templated.path_parameters.update({"baseurl": "https://graph.microsoft.com/v1.0", "user%2Did": "bob"}) + raw = RequestInformation(Method.GET) + + raw.url = "https://graph.microsoft.com/v1.0/me/messages?$skiptoken=abc" + + assert templated.url == "https://graph.microsoft.com/v1.0/users/bob/messages"