[Python-modules-team] Bug#637658: validators.Required() on IntegerField does not allow a value of "0"
Enrico Zini
enrico at debian.org
Sat Aug 13 14:24:10 UTC 2011
Package: python-wtforms
Version: 0.6.2-1
Severity: normal
Hello,
thank you for packaging wtforms.
I just found out, much to my frustration, that the Required validator
will not accept values of "0" in IntegerFields: the check it uses is a
simple "if not field.data" which obviously fails if field.data is 0.
Oddly, as a result the way to validate a required integer value is NOT
to use any validator. Since the IntegerField will call int() on any
value it gets (including the empty string), its default behavious is
to always require a value.
I did not find a way to have a "nullable" IntegerField that
accepts/returns integer values or None, which is what I would expect to
be the behaviour of IntegerField without a Required validator.
To summarise the behaviour I would expect:
# Integer field that can be left blank, returning either an int() or
# None
age = wtf.IntegerField("Age")
# Integer field that requires a value which can be any number,
# including 0, and always returns an int()
age = wtf.IntegerField("Age", wtf.validators.Required())
To summarise the behaviour I currently observe:
# Integer field that requires a value which can be any number,
# including 0, and always returns an int()
age = wtf.IntegerField("Age")
# Integer field that requires a value which can be any number,
# EXCLUDING 0, and always returns an int()
age = wtf.IntegerField("Age", wtf.validators.Required())
Ciao,
Enrico
-- System Information:
Debian Release: wheezy/sid
APT prefers stable-updates
APT policy: (500, 'stable-updates'), (500, 'testing')
Architecture: amd64 (x86_64)
Kernel: Linux 3.0.0-1-amd64 (SMP w/4 CPU cores)
Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Versions of packages python-wtforms depends on:
ii python 2.6.7-2 interactive high-level object-orie
ii python-support 1.0.14 automated rebuilding support for P
Versions of packages python-wtforms recommends:
ii libjs-jquery 1.6.2-1 JavaScript library for dynamic web
ii python-dateutil 1.4.1-4 powerful extensions to the standar
Versions of packages python-wtforms suggests:
ii python-django 1.3-2 High-level Python web development
ii python-sqlalchemy 0.6.8-1 SQL toolkit and Object Relational
-- no debconf information
More information about the Python-modules-team
mailing list