mirror of
https://github.com/django/django.git
synced 2025-11-07 07:15:35 +00:00
Fixed #27416 -- Prevented ModelFormSet from creating objects for invalid PKs in data.
This commit is contained in:
committed by
Tim Graham
parent
373140b07a
commit
181f492ad0
@@ -755,12 +755,13 @@ class BaseModelFormSet(BaseFormSet):
|
||||
forms_to_delete = self.deleted_forms
|
||||
for form in self.initial_forms:
|
||||
obj = form.instance
|
||||
# If the pk is None, it means either:
|
||||
# 1. The object is an unexpected empty model, created by invalid
|
||||
# POST data such as an object outside the formset's queryset.
|
||||
# 2. The object was already deleted from the database.
|
||||
if obj.pk is None:
|
||||
continue
|
||||
if form in forms_to_delete:
|
||||
# If the pk is None, it means that the object can't be
|
||||
# deleted again. Possible reason for this is that the
|
||||
# object was already deleted from the DB. Refs #14877.
|
||||
if obj.pk is None:
|
||||
continue
|
||||
self.deleted_objects.append(obj)
|
||||
self.delete_existing(obj, commit=commit)
|
||||
elif form.has_changed():
|
||||
|
||||
Reference in New Issue
Block a user