Opened 15 months ago

Closed 15 months ago

Last modified 15 months ago

#34317 closed Cleanup/optimization (fixed)

wrong attribute naming in method BaseModelFormSet.save_existing

Reported by: Maxim Danilov Owned by: Baha Sdtbekov
Component: Forms Version: dev
Severity: Normal Keywords: Formset, ModelFomset
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Maxim Danilov)

django.forms.models.py rows 654-667

we have a three methods:

    def save_new(self, form, commit=True):
        """Save and return a new model instance for the given form."""
        return form.save(commit=commit)

    def save_existing(self, form, instance, commit=True):
        """Save and return an existing model instance for the given form."""
        return form.save(commit=commit)

    def delete_existing(self, obj, commit=True):
        """Deletes an existing model instance."""
        if commit:
            obj.delete()

in delete_existing we have an "obj"
in save_existing we have an "instance"
why it is so? where the difference?

For ModelFormset in admin Inline we have also other instance: parent object. I can expected this "instance (parent)" instead of current "object".

My opinion: attribute name "instance" in save_existing should be changed on "obj"

Change History (9)

comment:1 by Maxim Danilov, 15 months ago

Description: modified (diff)
Summary: wrong variable naming in method BaseModelFormSet.save_existingwrong attribute naming in method BaseModelFormSet.save_existing

comment:2 by Carlton Gibson, 15 months ago

Triage Stage: UnreviewedAccepted

Hey Maxim, OK, yes. Where it's called the argument is obj, so +1 to making it consistent.
Want to make the PR?

Thanks.

comment:3 by Baha Sdtbekov, 15 months ago

Owner: changed from nobody to Baha Sdtbekov
Status: newassigned

in reply to:  2 comment:4 by Maxim Danilov, 15 months ago

Replying to Carlton Gibson:

Hey Maxim, OK, yes. Where it's called the argument is obj, so +1 to making it consistent.
Want to make the PR?

Thanks.

Yes Carlton. I want to try to made it.

comment:5 by Baha Sdtbekov, 15 months ago

comment:6 by Mariusz Felisiak, 15 months ago

Triage Stage: AcceptedReady for checkin
Version: 4.1dev

comment:7 by GitHub <noreply@…>, 15 months ago

Resolution: fixed
Status: assignedclosed

In 5f3c7b7e:

Fixed #34317 -- Renamed "instance" argument of BaseModelFormSet.save_existing() method.

in reply to:  7 comment:8 by Maxim Danilov, 15 months ago

Replying to GitHub <noreply@…>:

In 5f3c7b7e:

Fixed #34317 -- Renamed "instance" argument of BaseModelFormSet.save_existing() method.

Mariusz Felisiak was faster than me :*-(

Thank you.

comment:9 by Mariusz Felisiak, 15 months ago

Mariusz Felisiak was faster than me :*-(

Not me, I only merged PR prepared by Bakdolot.

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