,' \ ' "2016-01-01T00:00:00Z"^...">

date serialization failure · Issue #648 · RDFLib/rdflib (original) (raw)

The following code:

import rdflib g = rdflib.Graph() y = ' http://a.example/X http://a.example/p "2016-01-01T00:00:00"^^http://www.w3.org/2001/XMLSchema#dateTime,'
' "2016-01-01T00:00:00Z"^^http://www.w3.org/2001/XMLSchema#dateTime .'

p=g.parse(data=y, format="turtle") print(p.serialize(format="turtle").decode('utf-8'))

Causes an error:

  File "...lib/python3.5/site-packages/rdflib/term.py", line 822, in __gt__
    return self.value > other.value
TypeError: can't compare offset-naive and offset-aware datetimes

This is because the serializer is trying to sort the output tuples and the two different forms of date/time can't be compared.

Recommend the following change - line 822, term.py

        if self.value != None and other.value != None:
            try:
                return self.value > other.value
            except TypeError:
                return str(self.value) > str(other.value)

The idea being that, if the native comparison doesn't work, fall back on the string comparison.