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

Incorrect handling of falsy literals in SPARQLStore #2621

Open
eilmiv opened this issue Oct 17, 2023 · 1 comment
Open

Incorrect handling of falsy literals in SPARQLStore #2621

eilmiv opened this issue Oct 17, 2023 · 1 comment

Comments

@eilmiv
Copy link

eilmiv commented Oct 17, 2023

Failing example

from rdflib import Namespace, Graph, Literal
ex = Namespace("https://www.example.org/")
g = Graph("SPARQLStore")
g.open("http://localhost:9999/test/sparql")
print(list(
    g.triples((ex.a, ex.b, Literal("")))
))

... can produce ...

[(rdflib.term.URIRef('https://www.example.org/a'),
  rdflib.term.URIRef('https://www.example.org/b'),
  rdflib.term.Literal('')),
 (rdflib.term.URIRef('https://www.example.org/a'),
  rdflib.term.URIRef('https://www.example.org/b'),
  rdflib.term.URIRef('https://www.example.org/c'))]

... ex:a ex:b ex:c does not match (ex.a, ex.b, Literal(""))
(Literal(""), Literal(0), Literal(False) are treated as a variable)

Solution

These lines should compare to None (a.k.a. ANY) instead:


nts(o if o else Variable("o")),

@devkral
Copy link

devkral commented Oct 24, 2023

a maybe little off sidenote:

it maybe would be better to use "is None", "is not None" instead of using != == for None comparisons as None is an integer and things can break subtle. For example None == 0 would return True

This should be considered for a proper bugfix and maybe in some other code parts too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants