Code

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#2555 closed defect (wontfix)

[patch] Validators in BooleanField validator_list are called only when the field is set to True

Reported by: dk@… Owned by: adrian
Component: Validators Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Assume the following model:

def check_frobbyness( field_data, all_data):
	raise ValidationError, "Booh!"

class Frob( models.Model):
    is_frobby = models.BooleanField( _("Frobs OK"),  validator_list=[ check_frobbyness])    

The ValidationError occurs exactly when the checkbox is_frobby is checked in the admin, therefore validation is not possible for the "off" state.

Attachments (2)

checkfield_fix.patch (2.4 KB) - added by Manuel Saelices <msaelices at yaco dot es> 8 years ago.
Fixed... it uses Javascript but without JS behaviour is good (same behaviour than before patching)
checkfield_fix_v2.patch (3.6 KB) - added by Manuel Saelices <msaelices at yaco dot es> 8 years ago.
A cleaner solution... with a separated javascript file and more modular

Download all attachments as: .zip

Change History (5)

Changed 8 years ago by Manuel Saelices <msaelices at yaco dot es>

Fixed... it uses Javascript but without JS behaviour is good (same behaviour than before patching)

comment:1 Changed 8 years ago by anonymous

  • Summary changed from Validators in BooleanField validator_list are called only when the field is set to True to [patch] Validators in BooleanField validator_list are called only when the field is set to True

Changed 8 years ago by Manuel Saelices <msaelices at yaco dot es>

A cleaner solution... with a separated javascript file and more modular

comment:2 Changed 8 years ago by anonymous

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

Thanks for the patch, but I think this fix is a bit too heavy-handed for this case. If you want a validator to always run for a BooleanField, set the always_test attribute on the validator to True.

This feature is, admittedly, undocumented right at the moment, but that will be fixed shortly.

comment:3 Changed 8 years ago by mtredinnick

Sorry, that resolution decision was made by me. Was accidently not logged in.

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.