Permalink
Browse files

Fix mistaken stringification of "None" in `index()` calls that omit `…

…id`. Fix #90.
  • Loading branch information...
2 parents 450db73 + 835fad3 commit 146067e1aef806e91599782e74d5a6ab0c2c9192 @erikrose erikrose committed Mar 25, 2013
Showing with 17 additions and 4 deletions.
  1. +7 −0 docs/source/changelog.rst
  2. +2 −2 pyelasticsearch/client.py
  3. +8 −2 pyelasticsearch/tests.py
@@ -16,6 +16,13 @@ v0.5 (unreleased)
* Switch to the nose testrunner.
+v0.4.1 (2013-03-25)
+-----------------
+
+* Fix a bug introduced in 0.4 wherein "None" was accidentally sent to ES when
+ an ID wasn't passed to ``index()``.
+
+
v0.4 (2013-03-19)
-----------------
@@ -162,9 +162,9 @@ def _to_query(cls, obj):
" query string." % obj)
def _join_path(self, path_components):
- """Smush together the (string) path components, ignoring empty ones."""
+ """Smush together the path components, omitting '' and None ones."""
path = '/'.join(quote_plus(str(p), '') for p in path_components if
- len(str(p)))
+ p is not None and p != '')
if not path.startswith('/'):
path = '/' + path
View
@@ -54,10 +54,16 @@ def test_quoted_chars_in_id(self):
self.assert_result_contains(result, {'_type': 'test-type', '_id': """<>?,./`~!@#$%^&*()_+=[]\{{}|:";'""", 'ok': True, '_index': 'test-index'})
def test_indexing_without_id(self):
- result = self.conn.index('test-index', 'test-type', {'name': 'Joe Tester'})
- self.assert_result_contains(result, {'_type': 'test-type', 'ok': True, '_index': 'test-index'})
+ result = self.conn.index(
+ 'test-index', 'test-type', {'name': 'Joe Tester'})
+ self.assert_result_contains(result,
+ {'_type': 'test-type', 'ok': True, '_index': 'test-index'})
# should have an id of some value assigned.
ok_('_id' in result and result['_id'])
+ # should not generate the same id twice
+ result2 = self.conn.index(
+ 'test-index', 'test-type', {'name': 'Barny Tester'})
+ assert_not_equal(result['_id'], result2['_id'])
def test_explicit_index_create(self):
result = self.conn.create_index('test-index')

0 comments on commit 146067e

Please sign in to comment.