Opened 15 years ago

Closed 15 years ago

Last modified 13 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: dev
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

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 15 years ago.
12667.2.diff (3.6 KB ) - added by Ramiro Morales 15 years ago.
Correct patch. previous fix and test were totally bogus.

Download all attachments as: .zip

Change History (6)

by Ramiro Morales, 15 years ago

Attachment: 12667.diff added

comment:1 by Ramiro Morales, 15 years ago

Has patch: set
milestone: 1.2
Triage Stage: UnreviewedAccepted

by Ramiro Morales, 15 years ago

Attachment: 12667.2.diff added

Correct patch. previous fix and test were totally bogus.

comment:2 by thiggins, 15 years ago

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

comment:3 by jkocherhans, 15 years ago

Resolution: fixed
Status: newclosed

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

comment:4 by Jacob, 13 years ago

milestone: 1.2

Milestone 1.2 deleted

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