You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
from rdflib.graph import Graph, ConjunctiveGraph
from rdflib import URIRef, Namespace
ns = Namespace('http://example.org/')
store = ConjunctiveGraph(identifier='temp')
store.add((ns['abc'], ns['attribute'], 'qwer'))
store.serialize(destination='test.n3', format='n3')
Fails with:
Traceback (most recent call last):
File "test.py", line 7, in <module>
store.serialize(destination='test.n3', format='n3')
File "/usr/local/lib/python2.7/dist-packages/rdflib/graph.py", line 684, in serialize
serializer.serialize(stream, base=base, encoding=encoding, **args)
File "/usr/local/lib/python2.7/dist-packages/rdflib/plugins/serializers/turtle.py", line 180, in serialize
if self.statement(subject) and not firstTime:
File "/usr/local/lib/python2.7/dist-packages/rdflib/plugins/serializers/n3.py", line 91, in statement
or super(N3Serializer, self).statement(subject))
File "/usr/local/lib/python2.7/dist-packages/rdflib/plugins/serializers/turtle.py", line 239, in statement
return self.s_squared(subject) or self.s_default(subject)
File "/usr/local/lib/python2.7/dist-packages/rdflib/plugins/serializers/turtle.py", line 244, in s_default
self.predicateList(subject)
File "/usr/local/lib/python2.7/dist-packages/rdflib/plugins/serializers/turtle.py", line 342, in predicateList
self.objectList(properties[propList[0]])
File "/usr/local/lib/python2.7/dist-packages/rdflib/plugins/serializers/turtle.py", line 357, in objectList
self.path(objects[0], OBJECT)
File "/usr/local/lib/python2.7/dist-packages/rdflib/plugins/serializers/n3.py", line 95, in path
super(N3Serializer, self).path(node, position, newline)
File "/usr/local/lib/python2.7/dist-packages/rdflib/plugins/serializers/turtle.py", line 260, in path
or self.p_default(node, position, newline)):
File "/usr/local/lib/python2.7/dist-packages/rdflib/plugins/serializers/turtle.py", line 266, in p_default
self.write(self.label(node, position))
File "/usr/local/lib/python2.7/dist-packages/rdflib/plugins/serializers/turtle.py", line 279, in label
return self.getQName(node, position==VERB) or node.n3()
AttributeError: 'str' object has no attribute 'n3'
The problem is that the object of the added triple should be a rdflib.term.Literal instead of a str. But the error doesn't occur until serialize() is called. As a result it isn't really clear what or where the problem is. ConjunctiveStore.add() should check that tuple it is given for valid values.
The text was updated successfully, but these errors were encountered:
The question is only really where to raise the exception. I guess an isinstance(Node) check in graph.add is the best place.
We have a related issue with graph identifiers for the conjuctive graph for some stores, URIs given as strings are generally turned into URIRefs, but not always.
That's a good point. You don't want to have lots of paranoid code constantly checking types. My first intuition would be to deem some subset as the external API and check types there or at least clearly document what is and is not acceptable for parameters.
For example:
Fails with:
The problem is that the object of the added triple should be a rdflib.term.Literal instead of a str. But the error doesn't occur until serialize() is called. As a result it isn't really clear what or where the problem is. ConjunctiveStore.add() should check that tuple it is given for valid values.
The text was updated successfully, but these errors were encountered: