Merge pull request #2011 from bagerard/fix_batch_size_qs_clone

Fix queryset batch_size that wasn't copied to cloned queryset
This commit is contained in:
erdenezul 2019-03-10 21:22:46 +08:00 committed by GitHub
commit 1a863725d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 1 deletions

View File

@ -6,6 +6,7 @@ Development
=========== ===========
- (Fill this out as you fix issues and develop your features). - (Fill this out as you fix issues and develop your features).
- Fix .only() working improperly after using .count() of the same instance of QuerySet - Fix .only() working improperly after using .count() of the same instance of QuerySet
- Fix batch_size that was not copied when cloning a queryset object #2011
- POTENTIAL BREAKING CHANGE: All result fields are now passed, including internal fields (_cls, _id) when using `QuerySet.as_pymongo` #1976 - POTENTIAL BREAKING CHANGE: All result fields are now passed, including internal fields (_cls, _id) when using `QuerySet.as_pymongo` #1976
- Document a BREAKING CHANGE introduced in 0.15.3 and not reported at that time (#1995) - Document a BREAKING CHANGE introduced in 0.15.3 and not reported at that time (#1995)
- Fix InvalidStringData error when using modify on a BinaryField #1127 - Fix InvalidStringData error when using modify on a BinaryField #1127

View File

@ -757,7 +757,7 @@ class BaseQuerySet(object):
'_read_preference', '_iter', '_scalar', '_as_pymongo', '_read_preference', '_iter', '_scalar', '_as_pymongo',
'_limit', '_skip', '_hint', '_auto_dereference', '_limit', '_skip', '_hint', '_auto_dereference',
'_search_text', 'only_fields', '_max_time_ms', '_search_text', 'only_fields', '_max_time_ms',
'_comment') '_comment', '_batch_size')
for prop in copy_props: for prop in copy_props:
val = getattr(self, prop) val = getattr(self, prop)

View File

@ -394,6 +394,16 @@ class QuerySetTest(unittest.TestCase):
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
list(qs) list(qs)
def test_batch_size_cloned(self):
class A(Document):
s = StringField()
# test that batch size gets cloned
qs = A.objects.batch_size(5)
self.assertEqual(qs._batch_size, 5)
qs_clone = qs.clone()
self.assertEqual(qs_clone._batch_size, 5)
def test_update_write_concern(self): def test_update_write_concern(self):
"""Test that passing write_concern works""" """Test that passing write_concern works"""
self.Person.drop_collection() self.Person.drop_collection()