Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 106c190

Browse files
committed
Use unicode Null U+0000 in startkey for all docs iterator
1 parent c1fa2df commit 106c190

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/cloudant/database.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -630,18 +630,20 @@ def __iter__(self, remote=True):
630630
if not remote:
631631
super(CouchDatabase, self).__iter__()
632632
else:
633-
next_startkey = '0'
633+
# Use unicode Null U+0000 as the initial lower bound to ensure any
634+
# document id could exist in the results set.
635+
next_startkey = u'\u0000'
634636
while next_startkey is not None:
635637
docs = self.all_docs(
636-
limit=self._fetch_limit + 1, # Get one extra doc
637-
# to use as
638-
# next_startkey
638+
limit=self._fetch_limit,
639639
include_docs=True,
640640
startkey=next_startkey
641641
).get('rows', [])
642642

643-
if len(docs) > self._fetch_limit:
644-
next_startkey = docs.pop()['id']
643+
if len(docs) >= self._fetch_limit:
644+
# Ensure the next document batch contains ids that sort
645+
# strictly higher than the previous document id fetched.
646+
next_startkey = docs[-1]['id'] + u'\u0000'
645647
else:
646648
# This is the last batch of docs, so we set
647649
# ourselves up to break out of the while loop

0 commit comments

Comments
 (0)