diff options
| author | Hiroki Kiyohara <hirokiky@gmail.com> | 2016-12-07 03:06:58 +0900 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-12-06 13:06:58 -0500 |
| commit | 181f492ad021aeb43105aa9d38106ad7baf00211 (patch) | |
| tree | 4d9196fe20853ef3c2b741120fdc8b3e992765c8 /django/forms/models.py | |
| parent | 373140b07aa452946ccb6d5b0317fa09ed5bbdc2 (diff) | |
Fixed #27416 -- Prevented ModelFormSet from creating objects for invalid PKs in data.
Diffstat (limited to 'django/forms/models.py')
| -rw-r--r-- | django/forms/models.py | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/django/forms/models.py b/django/forms/models.py index 3d74225434..a0f3ff53b3 100644 --- a/django/forms/models.py +++ b/django/forms/models.py @@ -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(): |
