Opened 7 years ago

Closed 7 years ago

Last modified 5 years ago

#12667 closed (fixed)

changeset:12098 introduces choice validation bug at the model level

Reported by: anonymous Owned by: nobody
Component: Core (Other) Version: master
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Lines 200-202 of django/db/models/fields/init.py (introduced in changeset:12098) improperly handle the validation of choice fields.

if self._choices and value:
    if not value in dict(self.choices):
        raise exceptions.ValidationError(self.error_messages['invalid_choice'] % value)

This block does not account for grouped choices as described in the docs.
See the valid_value method of the ChoiceField class in /django/forms/fields.py for reference.

Attachments (2)

12667.diff (3.6 KB) - added by Ramiro Morales 7 years ago.
12667.2.diff (3.6 KB) - added by Ramiro Morales 7 years ago.
Correct patch. previous fix and test were totally bogus.

Download all attachments as: .zip

Change History (6)

Changed 7 years ago by Ramiro Morales

Attachment: 12667.diff added

comment:1 Changed 7 years ago by Ramiro Morales

Has patch: set
milestone: 1.2
Triage Stage: UnreviewedAccepted

Changed 7 years ago by Ramiro Morales

Attachment: 12667.2.diff added

Correct patch. previous fix and test were totally bogus.

comment:2 Changed 7 years ago by thiggins

I tested the second patch with my code and believe the problem is solved. Thank you, Ramiro. - Thomas B. Higgins

comment:3 Changed 7 years ago by jkocherhans

Resolution: fixed
Status: newclosed

(In [12374]) Fixed #12667. Added optgroup validation support to model fields with choices. Thanks ramiro.

comment:4 Changed 5 years ago by Jacob

milestone: 1.2

Milestone 1.2 deleted

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