Merge pull request #1784 from werat/fix_override_comment

Restore comment from cached value after queryset copy
This commit is contained in:
erdenezul 2018-05-19 09:23:58 +08:00 committed by GitHub
commit bb22287336
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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:
self._cursor_obj.batch_size(self._batch_size)
if self._comment is not None:
self._cursor_obj.comment(self._comment)
return self._cursor_obj
def __deepcopy__(self, memo):

View File

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