diff --git a/AUTHORS b/AUTHORS index d89c5a2e03..dbb2880613 100644 --- a/AUTHORS +++ b/AUTHORS @@ -35,6 +35,7 @@ answer newbie questions, and generally made Django that much better: Aleksi Häkli Alexander Dutton Alexander Myodov + Alexandr Tatarinov Alex Couper Alex Dedul Alex Gaynor diff --git a/django/db/models/fields/related_descriptors.py b/django/db/models/fields/related_descriptors.py index 4ae4bf5156..e69fd41e8a 100644 --- a/django/db/models/fields/related_descriptors.py +++ b/django/db/models/fields/related_descriptors.py @@ -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()) diff --git a/tests/many_to_one_null/tests.py b/tests/many_to_one_null/tests.py index 77b8fd7c25..6ccabefe66 100644 --- a/tests/many_to_one_null/tests.py +++ b/tests/many_to_one_null/tests.py @@ -85,6 +85,11 @@ class ManyToOneNullTests(TestCase): ['', '', ''] ) + 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