pyxb icon indicating copy to clipboard operation
pyxb copied to clipboard

TypeError: can't compare offset-naive and offset-aware datetimes

Open sherpya opened this issue 6 years ago • 3 comments

I have a type:

  <xs:simpleType name="DataFatturaType">
    <xs:restriction base="xs:date">
      <xs:minInclusive value="1970-01-01" />
    </xs:restriction>
  </xs:simpleType>

if the date in the xml I want to check has timezone the comparison fails (I had to raise the real error because it is being masked).

The date is 2019-01-11+01:00 and yes I known a date only with a timezone is pointless but iso8601 allows it, and someone apparently uses it, it would be better to strip timezone if date only

sherpya avatar Feb 11 '19 23:02 sherpya

As best I can tell PyXB correctly supports timezones for xsd:date instances and provides it through xsdRecoverableTzinfo.

Offhand it looks like this is a bug, but due to #100 this probably isn't going to get worked. It's slightly more likely to happen if you can attach a standalone test case to this issue.

It might also be related to the comparison value not having a timezone. One potential quick fix would be to use 1970-01-01Z. Dunno if it'd work, or if it'd just break comparison when there isn't a timezone, but it's worth a try.

pabigot avatar Feb 12 '19 00:02 pabigot

unfortunately using timezone aware constraint will fail comparison with non timezone aware values in xml, but since timezone in date only is pointless even for comparison, I suppose you can just drop the tzinfo value in the offset

sherpya avatar Feb 12 '19 10:02 sherpya

btw I can provide a testcase

sherpya avatar Feb 12 '19 10:02 sherpya