Code

Opened 6 years ago

Closed 6 years ago

Last modified 3 years ago

#7195 closed (fixed)

MultipleChoice fields don't validate when using request.REQUEST

Reported by: Daniel Roseman <daniel@…> Owned by: nobody
Component: Forms Version: master
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: UI/UX:

Description

MultipleChoice fields always give a validation error if you instantiate the form using data from request.REQUEST rather than request.POST.

This is because the SelectMultiple widget only uses the getlist() method if the data dictionary is a MultiValueDict, whereas request.REQUEST is a MergeDict.

Patch and tests attached.

Attachments (1)

mergedict.diff (2.2 KB) - added by Daniel Roseman <daniel@…> 6 years ago.

Download all attachments as: .zip

Change History (6)

Changed 6 years ago by Daniel Roseman <daniel@…>

comment:1 Changed 6 years ago by mattmcc

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 6 years ago by mir

  • milestone set to 1.0
  • Patch needs improvement set

I have one objection about the patch: It always treats a MergeDict like a MultiValueDict. But a MergeDict does not need to be merging MultiValueDicts. If it merges normal dicts, the patch is not appropriate.

Anyway, this is a bug so ==> milestone 1.0

comment:3 Changed 6 years ago by mtredinnick

I'm not really worried about people passing in a MergeDict of arbitrary dictionaries here. We don't need to publicly support every type of possible data structures, just the normal dictionary case and anything that Django might have to pass in internally. So this approach is fine.

comment:4 Changed 6 years ago by mtredinnick

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

(In [8525]) Fixed #7195 -- Fixed the validation of MultipleChoice fields so that they can
be populated from request.REQUEST. Based on a patch from Daniel Roseman.

comment:5 Changed 3 years ago by jacob

  • milestone 1.0 deleted

Milestone 1.0 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.