[Django] #33534: Formset form with initial values doesnt save

10 views
Skip to first unread message

Django

unread,
Feb 22, 2022, 9:22:13 AM2/22/22
to django-...@googlegroups.com
#33534: Formset form with initial values doesnt save
-------------------------------------+-------------------------------------
Reporter: | Owner: nobody
saschahofmann |
Type: Bug | Status: new
Component: Forms | Version: 4.0
Severity: Normal | Keywords: formset initial
Triage Stage: | save
Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-------------------------------------+-------------------------------------
Calling `formset.save()` on a formset with an extra_form that only hasn't
changed any of the initial values doesn't save.

I believe the cause is in
[https://github.com/django/django/blob/main/django/forms/models.py#L942].
`form.has_changed()` checks whether data is different compared to initial
values. This behaviour is incosistent with `form.save()` e.g. you could
call something like `formset.extra_forms[0].save()` and this would save
the form.

It seems reasonable to me to simple remove that line! Why would a new item
not be saved on Submit?

Happy to submit the according PR.

--
Ticket URL: <https://code.djangoproject.com/ticket/33534>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 22, 2022, 10:04:03 AM2/22/22
to django-...@googlegroups.com
#33534: Formset form with initial values doesnt save
-------------------------------------+-------------------------------------
Reporter: saschahofmann | Owner: nobody
Type: Bug | Status: closed
Component: Forms | Version: 4.0
Severity: Normal | Resolution: invalid

Keywords: formset initial | Triage Stage:
save | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* status: new => closed
* resolution: => invalid


Comment:

Formsets can have extra forms that may not be changed. In that case, they
shouldn't be treated as new data that the user submitted.

--
Ticket URL: <https://code.djangoproject.com/ticket/33534#comment:1>

Django

unread,
Feb 23, 2022, 2:28:51 AM2/23/22
to django-...@googlegroups.com
#33534: Formset form with initial values doesnt save
-------------------------------------+-------------------------------------
Reporter: saschahofmann | Owner: nobody
Type: Bug | Status: closed
Component: Forms | Version: 4.0
Severity: Normal | Resolution: invalid

Keywords: formset initial | Triage Stage:
save | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by saschahofmann):

I guess that makes sense if an extra_form is invalid/not filled out but if
I submit a correctly filled out form I would expect it to be saved or not?
Maybe it'd be nice to be able to configure that behaviour? Right now, I am
going to overwrite the save_new_objects function and remove the line.

Replying to [comment:1 Tim Graham]:


> Formsets can have extra forms that may not be changed. In that case,
they shouldn't be treated as new data that the user submitted.

--
Ticket URL: <https://code.djangoproject.com/ticket/33534#comment:2>

Django

unread,
Feb 23, 2022, 5:34:13 PM2/23/22
to django-...@googlegroups.com
#33534: Formset form with initial values doesnt save
-------------------------------------+-------------------------------------
Reporter: saschahofmann | Owner: nobody
Type: Bug | Status: closed
Component: Forms | Version: 4.0
Severity: Normal | Resolution: invalid

Keywords: formset initial | Triage Stage:
save | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham):

There's a discussion in #24541 which documented the behavior. I don't know
that the use case is common enough to warrant a new option. A set of
completely prefilled forms that require no input from the user seems quite
niche.

--
Ticket URL: <https://code.djangoproject.com/ticket/33534#comment:3>

Reply all
Reply to author
Forward
0 new messages