[spyne] primitive.DateTime: Attribute.validate_native problem

Roberto Maurizzi roberto.maurizzi at gmail.com
Mon Sep 29 07:28:45 UTC 2014


Hello everyone, first post on the list!

I'm trying to create a SOAP service that's able to accept requests from an
old Windows Mobile application that's sort-of unsupported: its SOAP is more
than a little funny but I've been able to work around most issues (I had to
use soft validation, etc.)

I'm stuck with a problem with a DateTime field: for some of the records the
application sends a <start_date>0001-01-01T00:00:00</start_date> field (no
TZ offset, and yes, it's datetime.datetime.min.

Processing the request I get a ValidationError raised from
spyne/protocol/xml.py after calling cls.validate_native.
This happens because in primitive.DateTime Attribute
classmethod validate_native the code checks if:

  value >  cls.Attributes.gt  and value >= cls.Attributes.ge

Since both Attributes.gt and Attributes.ge are set
as datetime.datetime(datetime.MINYEAR, 1, 1, 0, 0, 0, 0, spyne.LOCAL_TZ)
and spyne.LOCAL_TZ is set to UTC, the first test will fail (I'm using UTC
times too)because 0001-01-01 00:00:00+00:00 > 0001-01-01 00:00:00+00:00 is
False.

It's even more interesting if I try to use a timezone: if it's west of
Greenwich, the value >  cls.Attributes.gt test does pass. If they're east
of it, even value >= cls.Attributes.ge doesn't pass.

I'm particularly lucky (well... as someone having to work on this kind of
stuff can be ;-) ) because the backend only needs the date component and
working times are such that if I set a timezone of GMT-1, everything will
"work", but I wonder if there is a better solution to have this "special
datetime" pass validation...

(... please let me know if it's ok to use the list for this or I should've
used github: I'm posting here because it's not a clear problem and maybe
will need some discussion ).


Roberto Maurizzi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.spyne.io/archives/people/attachments/20140929/865544d9/attachment.html>


More information about the people mailing list