Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#4271 closed (wontfix)

Form should use a copy of data passed to it

Reported by: Gary Wilson <gary.wilson@…> Owned by: adrian
Component: Forms Version: master
Severity: Keywords:
Cc: Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


Usually, one passes POST data directly to the form like so:

if request.method == 'POST':
    form = MyForm(request.POST)

and request.POST is an immutable QueryDict. This means that you cannot fiddle with the data, for say if you wanted to remove keys so that the data doesn't get redisplayed when the form has errors.

I could make the copy in my own code:

form = MyForm(request.POST.copy())

but just thought this might be something useful to do more generally.

If anyone has a better alternative for not redisplaying submitted data, please mention it.

Attachments (1)

4271.diff (564 bytes) - added by Gary Wilson <gary.wilson@…> 9 years ago.
use copy of passed data.

Download all attachments as: .zip

Change History (4)

Changed 9 years ago by Gary Wilson <gary.wilson@…>

use copy of passed data.

comment:1 Changed 9 years ago by Gary Wilson <gary.wilson@…>

  • Has patch set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Design decision needed

comment:2 Changed 9 years ago by mtredinnick

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

Based on the the django-dev thread, this didn't get a lot of support from core developers. The logic was that
the copy operation is not free, so in the odd case when the developer wants to modify the data, they can make the copy manually (since it's not difficult).

comment:3 Changed 9 years ago by Gary Wilson <gary.wilson@…>

For those needing this, here would be a way to put it in your form so that the developer using your form doesn't need to know to pass a copy of the post data in the view:

class MyForm(forms.Form):
    def __init__(self, data=None, *args, **kwargs):
        if data:
            data = data.copy()
        super(MyForm, self).__init__(data, *args, **kwargs)
Note: See TracTickets for help on using tickets.
Back to Top