Permalink
Browse files

View: Don't try to create Document if doc is None

This occures when a view emits data with custom _id that actually does
not point to any document.
  • Loading branch information...
1 parent 73ff831 commit 32949d5a4b86e2c0cf5f529ba820958955392ce0 @nailor nailor committed Jun 8, 2011
Showing with 44 additions and 1 deletion.
  1. +43 −0 test/test_client.py
  2. +1 −1 trombi/client.py
View
@@ -1468,6 +1468,49 @@ def load_view_cb(result):
ioloop.start()
+@with_ioloop
+@with_couchdb
+def test_view_results_include_docs_with_bogus_docs(baseurl, ioloop):
+ def do_test(db):
+ def create_view_callback(response):
+ eq(response.code, 201)
+ db.set({'data': 'data'}, create_first_doc_cb)
+
+ def create_first_doc_cb(response):
+ db.set({'another': 'data'}, create_docs_cb)
+
+ def create_docs_cb(doc):
+ db.view('testview', 'all', load_view_cb, include_docs=True)
+
+ def load_view_cb(result):
+ eq(result.error, False)
+ eq(len(result), 2)
+ eq(result.total_rows, 2)
+ assert all(x['doc'] == None for x in result)
+ ioloop.stop()
+
+ db.server._fetch(
+ '%stestdb/_design/testview' % baseurl,
+ create_view_callback,
+ method='PUT',
+ body=json.dumps(
+ {
+ 'language': 'javascript',
+ 'views': {
+ 'all': {
+ 'map': 'function (doc) { emit(null, \
+ {"_id": "bogus"}) }',
+ }
+ }
+ }
+ )
+ )
+
+ s = trombi.Server(baseurl, io_loop=ioloop)
+ s.create('testdb', callback=do_test)
+ ioloop.start()
+
+
@with_ioloop
@with_couchdb
def test_bulk_insert(baseurl, ioloop):
View
@@ -742,7 +742,7 @@ def __init__(self, result, db=None):
self.offset = result.get('offset', 0)
def _format_row(self, row):
- if 'doc' in row:
+ if 'doc' in row and row['doc']:
row['doc'] = Document(self.db, row['doc'])
return row

0 comments on commit 32949d5

Please sign in to comment.