Fixed #29447 -- Made RelatedManager.set() pass bulk argument to clear().
This commit is contained in:
parent
6b3e17bab6
commit
7410618528
1
AUTHORS
1
AUTHORS
|
@ -35,6 +35,7 @@ answer newbie questions, and generally made Django that much better:
|
|||
Aleksi Häkli <aleksi.hakli@iki.fi>
|
||||
Alexander Dutton <dev@alexdutton.co.uk>
|
||||
Alexander Myodov <alex@myodov.com>
|
||||
Alexandr Tatarinov <tatarinov1997@gmail.com>
|
||||
Alex Couper <http://alexcouper.com/>
|
||||
Alex Dedul
|
||||
Alex Gaynor <alex.gaynor@gmail.com>
|
||||
|
|
|
@ -708,7 +708,7 @@ def create_reverse_many_to_one_manager(superclass, rel):
|
|||
db = router.db_for_write(self.model, instance=self.instance)
|
||||
with transaction.atomic(using=db, savepoint=False):
|
||||
if clear:
|
||||
self.clear()
|
||||
self.clear(bulk=bulk)
|
||||
self.add(*objs, bulk=bulk)
|
||||
else:
|
||||
old_objs = set(self.using(db).all())
|
||||
|
|
|
@ -85,6 +85,11 @@ class ManyToOneNullTests(TestCase):
|
|||
['<Article: Fourth>', '<Article: Second>', '<Article: Third>']
|
||||
)
|
||||
|
||||
def test_set_clear_non_bulk(self):
|
||||
# 2 queries for clear(), 1 for add(), and 1 to select objects.
|
||||
with self.assertNumQueries(4):
|
||||
self.r.article_set.set([self.a], bulk=False, clear=True)
|
||||
|
||||
def test_assign_clear_related_set(self):
|
||||
# Use descriptor assignment to allocate ForeignKey. Null is legal, so
|
||||
# existing members of the set that are not in the assignment set are
|
||||
|
|
Loading…
Reference in New Issue