I have just been digging into django.forms.models.py to debug my own code and found something which confuses me in both 1.8 and 1.9

django.forms.models.BaseModelFormSet.save_existing_objects() puts objects (child model instances) into the BaseModelFormSet.deleted_objects list whether they are deleted or not.

Here is the 1.9 code (no need to show 1.8 because they are both more or less the same)

741    def save_existing_objects(self, commit=True):
742        self.changed_objects = []
743        self.deleted_objects = []
744        if not self.initial_forms:
745            return []
746
747        saved_instances = []
748        forms_to_delete = self.deleted_forms
749        for form in self.initial_forms:
750            obj = form.instance
751            if form in forms_to_delete:
752                # If the pk is None, it means that the object can't be
753                # deleted again. Possible reason for this is that the
754                # object was already deleted from the DB. Refs #14877.
755                if obj.pk is None:
756                    continue
757                self.deleted_objects.append(obj)
758                self.delete_existing(obj, commit=commit)
759            elif form.has_changed():
760                self.changed_objects.append((obj, form.changed_data))
761 saved_instances.append(self.save_existing(form, obj, commit=commit))
762                if not commit:
763                    self.saved_forms.append(form)
764        return saved_instances

Line 758 will fail and the object will not be deleted if commit == False but line 757 has already added the object to a list.

Is this intended?

Thanks

Mike


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5676A047.1080000%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.

Reply via email to