From ae625ed5010a5df19833a4ab8d815935f44fab0c Mon Sep 17 00:00:00 2001 From: Aza Tulepbergenov Date: Thu, 10 Feb 2022 22:24:16 -0800 Subject: [PATCH] fix: adds more context to error message. --- google/api_core/path_template.py | 7 +++++-- tests/unit/test_path_template.py | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/google/api_core/path_template.py b/google/api_core/path_template.py index 41fbd4fe..b6284c85 100644 --- a/google/api_core/path_template.py +++ b/google/api_core/path_template.py @@ -270,7 +270,6 @@ def transcode(http_options, **request_kwargs): ] path_args = {field: get_field(request_kwargs, field) for field in path_fields} request["uri"] = expand(uri_template, **path_args) - # Remove fields used in uri path from request leftovers = copy.deepcopy(request_kwargs) for path_field in path_fields: @@ -297,4 +296,8 @@ def transcode(http_options, **request_kwargs): request["method"] = http_option["method"] return request - raise ValueError("Request obj does not match any template") + raise ValueError( + "Request {} does not match any URL path template in available HttpRule's {}".format( + request_kwargs, [opt["uri"] for opt in http_options] + ) + ) diff --git a/tests/unit/test_path_template.py b/tests/unit/test_path_template.py index 2c5216e0..c12b35fc 100644 --- a/tests/unit/test_path_template.py +++ b/tests/unit/test_path_template.py @@ -362,6 +362,7 @@ def test_transcode_with_additional_bindings( [[["get", "/v1/{name}", ""]], {"name": "first/last"}], [[["get", "/v1/{name=mr/*/*}", ""]], {"name": "first/last"}], [[["post", "/v1/{name}", "data"]], {"name": "first/last"}], + [[["post", "/v1/{first_name}", "data"]], {"last_name": "last"}], ], ) def test_transcode_fails(http_options, request_kwargs): @@ -385,5 +386,4 @@ def helper_test_transcode(http_options_list, expected_result_list): } if expected_result_list[2]: expected_result["body"] = expected_result_list[2] - return (http_options, expected_result)