Code

Opened 4 years ago

Closed 4 years ago

Last modified 3 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 4 years ago.
12667.2.diff (3.6 KB) - added by ramiro 4 years ago.
Correct patch. previous fix and test were totally bogus.

Download all attachments as: .zip

Change History (6)

Changed 4 years ago by ramiro

comment:1 Changed 4 years ago by ramiro

  • Has patch set
  • milestone set to 1.2
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

Changed 4 years ago by ramiro

Correct patch. previous fix and test were totally bogus.

comment:2 Changed 4 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 4 years ago by jkocherhans

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

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

comment:4 Changed 3 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 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.