mirror of
https://github.com/django/django.git
synced 2025-09-09 04:00:48 +00:00
Refs #36075 -- Adjusted pk_fields usage in bulk_update eligibility checks.
Regression in bf7b17d16d
.
Thanks Sage Abdullah for the report.
This commit is contained in:
parent
4bfec242b4
commit
161e79d277
2 changed files with 8 additions and 1 deletions
|
@ -878,7 +878,10 @@ class QuerySet(AltersData):
|
|||
fields = [self.model._meta.get_field(name) for name in fields]
|
||||
if any(not f.concrete or f.many_to_many for f in fields):
|
||||
raise ValueError("bulk_update() can only be used with concrete fields.")
|
||||
if any(f in self.model._meta.pk_fields for f in fields):
|
||||
all_pk_fields = set(self.model._meta.pk_fields)
|
||||
for parent in self.model._meta.all_parents:
|
||||
all_pk_fields.update(parent._meta.pk_fields)
|
||||
if any(f in all_pk_fields for f in fields):
|
||||
raise ValueError("bulk_update() cannot be used with primary key fields.")
|
||||
if not objs:
|
||||
return 0
|
||||
|
|
|
@ -144,6 +144,10 @@ class BulkUpdateTests(TestCase):
|
|||
with self.assertRaisesMessage(ValueError, self.pk_fields_error):
|
||||
CustomPk.objects.bulk_update([], ["name"])
|
||||
|
||||
def test_update_inherited_primary_key(self):
|
||||
with self.assertRaisesMessage(ValueError, self.pk_fields_error):
|
||||
SpecialCategory.objects.bulk_update([], ["id"])
|
||||
|
||||
def test_empty_objects(self):
|
||||
with self.assertNumQueries(0):
|
||||
rows_updated = Note.objects.bulk_update([], ["note"])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue