Skip to content

Commit

Permalink
Don't crash when the query_params kwarg to send_request is omitted. Fix
Browse files Browse the repository at this point in the history
#173.

Keep the null value of the kwarg as None for two reasons: (1) so we don't invalidate the docstring which says we can pass None and (2) because mutables as kwarg default values are asking for trouble.
  • Loading branch information
erikrose committed May 22, 2015
1 parent f22a235 commit fee4a09
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
6 changes: 6 additions & 0 deletions docs/source/changelog.rst
Expand Up @@ -2,6 +2,12 @@
Changelog
=========

v1.2.4 (2015-05-21)
-------------------
* Don't crash when the ``query_params`` kwarg is omitted from calls to
``send_request()``.


v1.2.3 (2015-04-17)
-------------------
* Make ``delete_all_indexes()`` work.
Expand Down
2 changes: 1 addition & 1 deletion pyelasticsearch/__init__.py
Expand Up @@ -14,7 +14,7 @@
__all__ = ['ElasticSearch', 'ElasticHttpError', 'Timeout', 'ConnectionError',
'ElasticHttpNotFoundError', 'IndexAlreadyExistsError', 'BulkError',
'InvalidJsonResponseError', 'bulk_chunks']
__version__ = '1.2.3'
__version__ = '1.2.4'
__version_info__ = tuple(__version__.split('.'))

get_version = lambda: __version_info__
2 changes: 2 additions & 0 deletions pyelasticsearch/client.py
Expand Up @@ -234,6 +234,8 @@ def send_request(self,
:arg query_params: A map of querystring param names to values or
``None``
"""
if query_params is None:
query_params = {}
path = self._join_path(path_components)

# We wrap to use pyelasticsearch's exception hierarchy for backward
Expand Down
5 changes: 5 additions & 0 deletions pyelasticsearch/tests/client_tests.py
Expand Up @@ -390,6 +390,11 @@ def test_percolate(self):
result = self.conn.percolate('test-index', 'test-type', document)
self.assert_result_contains(result, {'matches': []})

def test_send_request_without_query_params(self):
"""Demonstrate that omitting the query_params kwarg to send_request
doesn't try to call iteritems() on None."""
self.conn.send_request('GET', [])


class SearchTestCase(ElasticSearchTestCase):
def setUp(self):
Expand Down

0 comments on commit fee4a09

Please sign in to comment.