diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d7be463..2ca569f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -73,6 +73,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Updates `master` to `cluster_manager` to be inclusive ([#242](https://github.com/opensearch-project/opensearch-py/pull/242)) - Support a custom signing service name for AWS SigV4 ([#268](https://github.com/opensearch-project/opensearch-py/pull/268)) - Updated CI tests to make them work locally ([#275](https://github.com/opensearch-project/opensearch-py/pull/275)) +- Fix bug with validation of 'timeout' parameter ([#387](Do not escape the "timeout" parameter.)) ### Deprecated ### Removed @@ -86,4 +87,5 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) [2.0.1]: https://github.com/opensearch-project/opensearch-py/compare/v2.0.0...v2.0.1 [2.1.0]: https://github.com/opensearch-project/opensearch-py/compare/v2.0.1...v2.1.0 [2.1.1]: https://github.com/opensearch-project/opensearch-py/compare/v2.1.0...v2.1.1 -[2.2.0]: https://github.com/opensearch-project/opensearch-py/compare/v2.1.1...v2.2.0 \ No newline at end of file +[2.2.0]: https://github.com/opensearch-project/opensearch-py/compare/v2.1.1...v2.2.0 + diff --git a/opensearchpy/client/utils.py b/opensearchpy/client/utils.py index e79b6e9e..a5e99b11 100644 --- a/opensearchpy/client/utils.py +++ b/opensearchpy/client/utils.py @@ -165,16 +165,17 @@ def query_params(*opensearch_query_params): elif api_key is not None: headers["authorization"] = "ApiKey %s" % (_base64_auth_header(api_key),) + # don't escape ignore, request_timeout, or timeout + for p in ("ignore", "request_timeout", "timeout"): + if p in kwargs: + params[p] = kwargs.pop(p) + for p in opensearch_query_params + GLOBAL_PARAMS: if p in kwargs: v = kwargs.pop(p) if v is not None: params[p] = _escape(v) - # don't treat ignore, request_timeout, and opaque_id as other params to avoid escaping - for p in ("ignore", "request_timeout"): - if p in kwargs: - params[p] = kwargs.pop(p) return func(*args, params=params, headers=headers, **kwargs) return _wrapped diff --git a/test_opensearchpy/test_client/test_utils.py b/test_opensearchpy/test_client/test_utils.py index 2b5e5a39..1a4b6809 100644 --- a/test_opensearchpy/test_client/test_utils.py +++ b/test_opensearchpy/test_client/test_utils.py @@ -85,6 +85,31 @@ class TestQueryParams(TestCase): self.func_to_wrap(headers={"X": "y"}) self.assertEqual(self.calls[-1], ((), {"params": {}, "headers": {"x": "y"}})) + def test_non_escaping_params(self): + # the query_params decorator doesn't validate "timeout" it simply avoids escaping as it did + self.func_to_wrap(simple_param="x", timeout="4s") + self.assertEqual( + self.calls[-1], + ((), {"params": {"simple_param": b"x", "timeout": "4s"}, "headers": {}}), + ) + + self.func_to_wrap(simple_param="x", timeout=4, ignore=5, request_timeout=6) + self.assertEqual( + self.calls[-1], + ( + (), + { + "params": { + "simple_param": b"x", + "timeout": 4, + "ignore": 5, + "request_timeout": 6, + }, + "headers": {}, + }, + ), + ) + def test_per_call_authentication(self): self.func_to_wrap(api_key=("name", "key")) self.assertEqual(