PYTHON-2719 RawBatchCursor must raise StopIteration instead of returning empty bytes when the cursor contains no results (#624)

This commit is contained in:
Prashant Mital 2021-05-17 13:58:06 -07:00 committed by GitHub
parent ac61cf87a9
commit 048ee81836
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -1526,7 +1526,9 @@ class _OpReply(object):
error_object.get("$err"),
error_object.get("code"),
error_object)
return [self.documents]
if self.documents:
return [self.documents]
return []
def unpack_response(self, cursor_id=None,
codec_options=_UNICODE_REPLACE_CODEC_OPTIONS,

View File

@ -1471,7 +1471,14 @@ class TestRawBatchCursor(IntegrationTest):
explanation = c.find_raw_batches().explain()
self.assertIsInstance(explanation, dict)
def test_empty(self):
self.db.test.drop()
cursor = self.db.test.find_raw_batches()
with self.assertRaises(StopIteration):
next(cursor)
def test_clone(self):
self.db.test.insert_one({})
cursor = self.db.test.find_raw_batches()
# Copy of a RawBatchCursor is also a RawBatchCursor, not a Cursor.
self.assertIsInstance(next(cursor.clone()), bytes)