Skip to content

Commit cb78f44

Browse files
committed
Fix descending in iterview.
1 parent ba09f1c commit cb78f44

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

couchdb/client.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -856,8 +856,11 @@ def iterview(self, name, batch, wrapper=None, **options):
856856
while True:
857857
loop_limit = min(limit or batch, batch)
858858
# Get rows in batches, with one extra for start of next batch.
859-
options.update(limit=loop_limit + 1, startkey=startkey,
860-
startkey_docid=startkey_docid)
859+
options.update(limit=loop_limit + 1)
860+
# Add start keys, if any.
861+
if startkey is not None: # XXX todo: None is a valid key value
862+
options.update(startkey=startkey,
863+
startkey_docid=startkey_docid)
861864
rows = list(self.view(name, wrapper, **options))
862865
# Yield rows from this batch.
863866
for row in itertools.islice(rows, loop_limit):

couchdb/tests/client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,12 @@ def test_limit(self):
776776
self.assertEqual([self.docfromrow(doc) for doc in self.db.iterview('test/nums', limit, limit=limit)],
777777
[self.docfromnum(x) for x in xrange(limit)])
778778

779+
def test_descending(self):
780+
self.assertEqual([self.docfromrow(doc) for doc in self.db.iterview('test/nums', 10, descending=True)],
781+
[self.docfromnum(x) for x in xrange(self.num_docs - 1, -1, -1)])
782+
self.assertEqual([self.docfromrow(doc) for doc in self.db.iterview('test/nums', 10, limit=int(self.num_docs / 4), descending=True)],
783+
[self.docfromnum(x) for x in xrange(self.num_docs - 1, int(self.num_docs * 3 / 4) - 1, -1)])
784+
779785

780786
def suite():
781787
suite = unittest.TestSuite()

0 commit comments

Comments
 (0)