Restore comment from cached value after cursor copy

This commit is contained in:
Andy Yankovsky 2018-05-07 23:17:12 +03:00
parent 317e844886
commit 5a6d4387ea
2 changed files with 13 additions and 5 deletions

View File

@ -1579,6 +1579,9 @@ class BaseQuerySet(object):
if self._batch_size is not None: if self._batch_size is not None:
self._cursor_obj.batch_size(self._batch_size) self._cursor_obj.batch_size(self._batch_size)
if self._comment is not None:
self._cursor_obj.comment(self._comment)
return self._cursor_obj return self._cursor_obj
def __deepcopy__(self, memo): def __deepcopy__(self, memo):

View File

@ -2383,14 +2383,19 @@ class QuerySetTest(unittest.TestCase):
age = IntField() age = IntField()
with db_ops_tracker() as q: with db_ops_tracker() as q:
adult = (User.objects.filter(age__gte=18) adult1 = (User.objects.filter(age__gte=18)
.comment('looking for an adult') .comment('looking for an adult')
.first()) .first())
adult2 = (User.objects.comment('looking for an adult')
.filter(age__gte=18)
.first())
ops = q.get_ops() ops = q.get_ops()
self.assertEqual(len(ops), 1) self.assertEqual(len(ops), 2)
op = ops[0] for op in ops:
self.assertEqual(op['query']['$query'], {'age': {'$gte': 18}}) self.assertEqual(op['query']['$query'], {'age': {'$gte': 18}})
self.assertEqual(op['query']['$comment'], 'looking for an adult') self.assertEqual(op['query']['$comment'], 'looking for an adult')
def test_map_reduce(self): def test_map_reduce(self):
"""Ensure map/reduce is both mapping and reducing. """Ensure map/reduce is both mapping and reducing.