sebastian-ardila / google-app-engine-django

Automatically exported from code.google.com/p/google-app-engine-django
Apache License 2.0
0 stars 0 forks source link

Can't validate a form with a required boolean property that is False #148

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
A ModelForm derived from a Model with a required BoolProperty has a
checkbox. But if you submit the form with the checkbox unchecked (because
you want the property to be False) the form won't validate.

An app which demonstrates this is attached.  It's very simple and more or
less straight out of "Using the Google App Engine Helper for Django"
http://code.google.com/appengine/articles/appengine_helper_for_django.html

Try to submit the form with the checkbox unchecked.  You will get "this
field is required".

I suspect somewhere in the code someone used "if x" when they mean "if x !=
None".  (This is one of my beefs with Python.)  Code review should pick
that up.

Original issue reported on code.google.com by richard....@gmail.com on 16 Dec 2009 at 8:49

Attachments:

GoogleCodeExporter commented 9 years ago
In newforms/fields.py, Field.clean raises ValidationError if a value is None. 
This is 
called by BooleanField.clean which calls its super. But a checkbox that is 
unchecked 
will make the value None, because it just omits it from the CGI parameters. So 
this is 
a bug in newforms.

Workaround: Make a BooleanField that does not call its super, like this:

class MyBooleanField(fields.Field):
    widget = forms.CheckboxInput
    def clean(self, value):
        return bool(value)

Google, maybe this is fixed in later Django? Need to update Django or 
back-patch.

Original comment by mimika...@gmail.com on 18 Dec 2009 at 7:05

GoogleCodeExporter commented 9 years ago
This is a Django bug, nothing in the helper code changes this behaviour as far 
as I can tell.

Original comment by m...@google.com on 8 Jun 2010 at 12:02

GoogleCodeExporter commented 9 years ago
This is a problem with the app-engine service, and there is nothing a user can 
do to fix it, so it is not correct to close it even if it comes from third 
party software that you supply. The bug will still exist.

Original comment by mimika...@gmail.com on 9 Jun 2010 at 10:06

GoogleCodeExporter commented 9 years ago
If you can demonstrate a bug in the helper code, or supply a patch then it will 
be welcomed.

Bugs in Django itself need to be fixed in Django.

Original comment by m...@google.com on 10 Jun 2010 at 1:48