[spyne] primitive.DateTime: Attribute.validate_native problem

Burak Arslan burak.arslan at arskom.com.tr
Mon Sep 29 10:28:08 UTC 2014

On 09/29/14 10:28, Roberto Maurizzi wrote:
> Hello everyone, first post on the list!

Hello Roberto, Welcome!

> 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 <http://cls.Attributes.gt>  and value >=
> cls.Attributes.ge <http://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.

Hmmm. That's python's fault for making boundary values valid ones.

Maybe we can skip gt (and lt) test when it's equal to smallest (and
largest) datetime?

        return SimpleModel.validate_native(cls, value) and (
            value is None or (
                    (cls.Attributes.gt is cls._min_dt or value >
                and value >= cls.Attributes.ge
                and (cls.Attributes.lt is cls._max_dt or value <
                and value <= cls.Attributes.le

Do you think that'd be enough?

> (... 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 ).

it's perfectly fine to use the list. we will file an issue if it's needed.

best regards,

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

More information about the people mailing list