Code

Opened 5 years ago

Closed 5 years ago

Last modified 3 years ago

#9609 closed (fixed)

(Null)BooleanField does not clean data correctly for MySQL with all widgets

Reported by: psagers Owned by: nobody
Component: Forms Version: 1.0
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

MySQL represents boolean values as 0 and 1, as the BooleanField documentation warns. This is not an issue when using a NullBooleanSelect widget, as NullBooleanSelect translates between model values and arbitrary integers for use in a form. However, not all choice widgets do this and thus they rely on the model values matching the widget values in order to populate initial widget state for rendering. The form field, in turn, must be able to clean the resulting form values. In order to support MySQL, therefore, (Null)BooleanField must understand '0' and '1'.

Ticket 7753 added support for using HiddenWidget with the boolean fields, which addresses the general problem of cleaning raw form values. The attached patch adds '0' and '1' to the list of recognized values.

Attachments (1)

mysql_compat.diff (2.7 KB) - added by psagers 5 years ago.

Download all attachments as: .zip

Change History (6)

Changed 5 years ago by psagers

comment:1 Changed 5 years ago by psagers

  • Component changed from Uncategorized to Forms
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Version changed from SVN to 1.0

comment:2 Changed 5 years ago by jacob

  • milestone set to 1.1
  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 5 years ago by russellm

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

(In [10660]) Fixed #9609 -- Modified the clean method of(Null)Boolean field to accept '1' and '0' as valid inputs. Thanks to psagers for the patch.

This is required to support the use of non-default form widgets such as RadioSelect when the data comes from MySQL, which uses 1/0 to represent booleans.

comment:4 Changed 5 years ago by russellm

(In [10662]) Fixed #9609 -- Modified the clean method of(Null)Boolean field to accept '1' and '0' as valid inputs. Thanks to psagers for the patch.

This is required to support the use of non-default form widgets such as RadioSelect when the data comes from MySQL, which uses 1/0 to represent booleans.

Merge of r10660 from trunk.

comment:5 Changed 3 years ago by jacob

  • milestone 1.1 deleted

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