From f38fa51fea4e0b23054509a8e6feb8fb486209e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Honza=20Kr=C3=A1l?= Date: Tue, 17 Jan 2017 03:10:18 +0100 Subject: [PATCH] When user is passing params we need to make a copy Fixes #517 --- elasticsearch/client/utils.py | 4 +++- test_elasticsearch/test_client/__init__.py | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/elasticsearch/client/utils.py b/elasticsearch/client/utils.py index 2327d823..5500128a 100644 --- a/elasticsearch/client/utils.py +++ b/elasticsearch/client/utils.py @@ -57,7 +57,9 @@ def query_params(*es_query_params): def _wrapper(func): @wraps(func) def _wrapped(*args, **kwargs): - params = kwargs.pop('params', {}) + params = {} + if 'params' in kwargs: + params = kwargs.pop('params').copy() for p in es_query_params + GLOBAL_PARAMS: if p in kwargs: v = kwargs.pop(p) diff --git a/test_elasticsearch/test_client/__init__.py b/test_elasticsearch/test_client/__init__.py index dacf8e42..4bf2978c 100644 --- a/test_elasticsearch/test_client/__init__.py +++ b/test_elasticsearch/test_client/__init__.py @@ -54,6 +54,21 @@ class TestClient(ElasticsearchTestCase): calls = self.assert_url_called('HEAD', '/') self.assertEquals([({'request_timeout': .1}, None)], calls) + def test_params_is_copied_when(self): + rt = object() + params = dict(request_timeout=rt) + self.client.ping(params=params) + self.client.ping(params=params) + calls = self.assert_url_called('HEAD', '/', 2) + self.assertEquals( + [ + ({'request_timeout': rt}, None), + ({'request_timeout': rt}, None) + ], + calls + ) + self.assertFalse(calls[0][0] is calls[1][0]) + def test_from_in_search(self): self.client.search(index='i', doc_type='t', from_=10) calls = self.assert_url_called('GET', '/i/t/_search')