Opened 4 years ago

Closed 20 months ago

Last modified 19 months ago

#16869 closed Bug (fixed)

BaseGenericInlineFormSet does not use form's save() method

Reported by: mattaustin Owned by: pyriku
Component: contrib.contenttypes Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

Changeset [12268] introduced the save_new() method on BaseGenericInlineFormSet - however this uses creates a new object based on self.model and thehn uses save_instance(), bypassing any custom code on the form's save() method.

Would the following not provide the same functionality and honor the form's save() method?

    def save_new(self, form, commit=True):
        setattr(form.instance, self.ct_field.get_attname(),
            ContentType.objects.get_for_model(self.instance).pk)
        setattr(form.instance, self.ct_fk_field.get_attname(),
            self.instance.pk)
        return form.save(commit=commit)

Attachments (1)

save_new_using_form_save.patch (1.1 KB) - added by pyriku 4 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 Changed 4 years ago by pyriku

  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to pyriku
  • Patch needs improvement unset

Changed 4 years ago by pyriku

comment:2 Changed 4 years ago by pyriku

  • Has patch set

Attached the patch as described.

comment:3 Changed 4 years ago by pyriku

  • Triage Stage changed from Unreviewed to Accepted

comment:4 Changed 2 years ago by ramiro

  • Needs documentation set
  • Needs tests set

comment:5 Changed 20 months ago by polmuz

  • Needs documentation unset
  • Needs tests unset

I added a test for the patch provided by pyriku and created a pull request with it. https://github.com/django/django/pull/1599

comment:6 Changed 20 months ago by Tim Graham <timograham@…>

  • Resolution set to fixed
  • Status changed from new to closed

In b11564fd36587b1077bf7d77b62b7879cc08c382:

Fixed #16869 -- BaseGenericInlineFormSet.save_new should use form's save() method

Thanks mattaustin for the report and Pablo Recio (pyriku) for the patch.

comment:7 Changed 19 months ago by mattaustin

Thanks for the patch/commit. Any chance of this being cherry-picked to Django 1.6, or are we too late?

Note: See TracTickets for help on using tickets.
Back to Top