Formulator DateTime validation bug
[email protected] Tue, 20 Jul 2004 19:55:50 +0200
| Newsgroups | gmane.comp.web.zope.formulator.devel |
|---|---|
| Message-ID | <[email protected]> |
--h31gzZEtNLTqOjlF
Content-Type: text/plain; charset=iso-8859-2
Content-Disposition: inline
Formulator has a DateTime field validation bugs.
As far as I understand, validate error should be raised
when DateTime field value is not a valid date time - that
is obvious. Exactly this happens when you leave field blank.
The same should happen, when you specify (for example) too
big hour od too big month.
Formulator creates DateTime object from form's input.
It catches some string exceptions to detect invalid date (time)
input. However, Zope's DateTime object raises
DateError or TimeError, not string exceptions, at least recent
versions of Zope (2.7+) do.
Two patches that fix this issue in two different
ways are attached to this message.
I don't know whether DateError and TimeError are new in Zope.
It might be that DateTime did raise string exceptions in
earlier versions of Zope.
If this is true, the first (conditional) patch detects
whether DateError and TimeError exceptions exist
and can be imported, so Formulator will (I hope) still work
with older versions of Zope.
If DateError and TimeError are usual and "standard"
ways to indicate datetime parsing error,
the second patch just adds those exceptions
to the list of caught exceptions.
Please take a few seconds to review this
and apply this to CVS version if patches are good.
Releasing new version of Formulator that fixes this issue
would be very helpful.
These bugs affect functionality of Formulator - it simply fails
to validate form input and "brakes down" (throwing "strange"
exceptions from validate_all is not an expected behaviour).
Sure, one could surround validate_all with try-except block, but
this is not documented anywhere and it lacks information
about which field didn't validate properly.
I am not familiar with the "procedure" of open source develompent
and bug reporting, so I'm sending this to formulator-dev list AND
submiting bug at sf.net.
Sorry if this causes confusion.
Hope that helps.
Thanks for the good work.
Bye.
--
Maciej Pietrzak
--h31gzZEtNLTqOjlF
Content-Type: text/plain; charset=iso-8859-2
Content-Disposition: attachment;
filename="formulator_conditional_date-error.patch"
? .Validator.py.swp
Index: Validator.py
===================================================================
RCS file: /cvs/infrae/Formulator/Validator.py,v
retrieving revision 1.39
diff -u -r1.39 Validator.py
--- Validator.py 8 Mar 2004 11:31:07 -0000 1.39
+++ Validator.py 20 Jul 2004 16:12:22 -0000
@@ -8,6 +8,18 @@
from Errors import ValidationError
from helpers import is_sequence
+try:
+ from DateTime.DateTime import DateError
+ _have_date_error = True
+except ImportError:
+ _have_date_error = False
+
+try:
+ from DateTime.DateTime import TimeError
+ _have_time_error = True
+except ImportError:
+ _have_time_error = False
+
class ValidatorBase:
"""Even more minimalistic base class for validators.
"""
@@ -681,10 +693,14 @@
elif ampm == 'pm' and hour < 12:
hour += 12
+ exceptions_to_catch = ('DateTimeError', 'Invalid Date Components', 'TimeError')
+ if _have_date_error: exceptions_to_catch += (DateError, )
+ if _have_time_error: exceptions_to_catch += (TimeError, )
+
try:
result = DateTime(int(year), int(month), int(day), hour, minute)
# ugh, a host of string based exceptions
- except ('DateTimeError', 'Invalid Date Components', 'TimeError'):
+ except exceptions_to_catch:
self.raise_error('not_datetime', field)
# check if things are within range
--h31gzZEtNLTqOjlF
Content-Type: text/plain; charset=iso-8859-2
Content-Disposition: attachment;
filename="formulator_unconditional_date-error.patch"
? .Validator.py.swp
Index: Validator.py
===================================================================
RCS file: /cvs/infrae/Formulator/Validator.py,v
retrieving revision 1.39
diff -u -r1.39 Validator.py
--- Validator.py 8 Mar 2004 11:31:07 -0000 1.39
+++ Validator.py 20 Jul 2004 16:18:36 -0000
@@ -684,7 +684,8 @@
try:
result = DateTime(int(year), int(month), int(day), hour, minute)
# ugh, a host of string based exceptions
- except ('DateTimeError', 'Invalid Date Components', 'TimeError'):
+ except ('DateTimeError', 'Invalid Date Components', 'TimeError',
+ DateTime.DateError, DateTime.TimeError):
self.raise_error('not_datetime', field)
# check if things are within range
--h31gzZEtNLTqOjlF
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
formulator-dev mailing list
formulator-dev-IAPFreCvJWM6s/[email protected]
http://lists.infrae.com/mailman/listinfo/formulator-dev
--h31gzZEtNLTqOjlF--