Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad SPARQLStore handling of empty literals #457

Closed
bcroq opened this issue Feb 23, 2015 · 2 comments · Fixed by #459
Closed

Bad SPARQLStore handling of empty literals #457

bcroq opened this issue Feb 23, 2015 · 2 comments · Fixed by #459
Labels
bug Something isn't working SPARQL store Related to a store.
Milestone

Comments

@bcroq
Copy link
Contributor

bcroq commented Feb 23, 2015

When an empty literal is returned to a SPARQLStore, it becomes an rdflib.term.Literal(u'None') instead of an rdflib.term.Literal(u''):

# ./fuseki-server --update --mem /empty_literal

import rdflib
from rdflib.plugins.stores.sparqlstore import SPARQLUpdateStore

store = SPARQLUpdateStore('http://fuseki.til.io:3030/empty_literal/query',
                          'http://fuseki.til.io:3030/empty_literal/update')

graph = rdflib.Graph(store, 'http://example.com/')

graph.add((rdflib.URIRef('http://example.com/s'), 
           rdflib.URIRef('http://example.com/p'), 
           rdflib.Literal('')))

o = tuple(graph)[0][2]
assert o == rdflib.Literal(''), repr(o)

raises an AssertionError: rdflib.term.Literal(u'None')

The problem seems to be in rdflib.plugins.stores.sparqlstore:CastToTerm:

import io
from xml.etree import ElementTree

import rdflib
from rdflib.plugins.stores.sparqlstore import CastToTerm

s = """<ns0:literal xmlns:ns0="http://www.w3.org/2005/sparql-results#" />"""
node = ElementTree.parse(io.BytesIO(s)).getroot()
term = CastToTerm(node)
assert term  == rdflib.Literal(''), repr(term)

raises an AssertionError: rdflib.term.Literal(u'None')

@joernhees
Copy link
Member

@gjhiggins could you review the changes in #459 ? There is some weird if False in the segment i patched

@bcroq
Copy link
Contributor Author

bcroq commented Feb 25, 2015

@joernhees I confirm that the changes in #459 fix the problem.

joernhees added a commit to joernhees/rdflib that referenced this issue Feb 25, 2015
joernhees added a commit to joernhees/rdflib that referenced this issue Feb 25, 2015
joernhees added a commit that referenced this issue Feb 25, 2015
SPARQLStore does not transform Literal('') into Literal('None') anymore, fixes #457
@joernhees joernhees added store Related to a store. SPARQL labels Feb 26, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working SPARQL store Related to a store.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants