Skip to content

Commit 0536316

Browse files
committed
Fix iterview for views with null keys.
1 parent a3483e2 commit 0536316

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

couchdb/client.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -852,17 +852,10 @@ def iterview(self, name, batch, wrapper=None, **options):
852852
limit = options.get('limit')
853853
if limit is not None and limit <= 0:
854854
raise ValueError('limit must be 1 or more')
855-
startkey, startkey_docid = (options.get('startkey'),
856-
options.get('startkey_docid'))
857855
while True:
858856
loop_limit = min(limit or batch, batch)
859857
# Get rows in batches, with one extra for start of next batch.
860858
options['limit'] = loop_limit + 1
861-
# Add start keys, if any.
862-
if startkey is not None: # XXX todo: None is a valid key value
863-
options['startkey'] = startkey
864-
if startkey_docid is not None:
865-
options['startkey_docid'] = startkey_docid
866859
rows = list(self.view(name, wrapper, **options))
867860
# Yield rows from this batch.
868861
for row in itertools.islice(rows, loop_limit):
@@ -873,8 +866,8 @@ def iterview(self, name, batch, wrapper=None, **options):
873866
# Check if there is nothing else to yield.
874867
if len(rows) <= batch or (limit is not None and limit == 0):
875868
break
876-
# Save start keys for next loop.
877-
startkey, startkey_docid = rows[-1]['key'], rows[-1]['id']
869+
# Update options with start keys for next loop.
870+
options.update(startkey=rows[-1]['key'], startkey_docid=rows[-1]['id'])
878871

879872
def show(self, name, docid=None, **options):
880873
"""Call a 'show' function.

couchdb/tests/client.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,8 @@ def docfromrow(self, row):
741741
def setUp(self):
742742
super(ViewIterationTestCase, self).setUp()
743743
design_doc = {'_id': '_design/test',
744-
'views': {'nums': {'map': 'function(doc) {emit(doc.num, null);}'}}}
744+
'views': {'nums': {'map': 'function(doc) {emit(doc.num, null);}'},
745+
'nulls': {'map': 'function(doc) {emit(null, null);}'}}}
745746
self.db.save(design_doc)
746747
self.db.update([self.docfromnum(num) for num in xrange(self.num_docs)])
747748

@@ -788,6 +789,9 @@ def test_startkey(self):
788789
self.assertEqual([self.docfromrow(doc) for doc in self.db.iterview('test/nums', 10, startkey=1, descending=True)],
789790
[self.docfromnum(x) for x in xrange(3, -1, -1)])
790791

792+
def test_nullkeys(self):
793+
self.assertEqual(len(list(self.db.iterview('test/nulls', 10))), self.num_docs)
794+
791795

792796
def suite():
793797
suite = unittest.TestSuite()

0 commit comments

Comments
 (0)