RDFLib / rdflib

RDFLib is a Python library for working with RDF, a simple yet powerful language for representing information.
https://rdflib.readthedocs.org
BSD 3-Clause "New" or "Revised" License
2.18k stars 558 forks source link

SPARQL: dataset update does not support variable substitution for graph ref #2141

Open davidatsamp opened 2 years ago

davidatsamp commented 2 years ago

SPARQL update with a binding variable for the graph URI seems not to work properly:

import rdflib
from rdflib.plugins.stores.memory import Memory

store = Memory()

graph = rdflib.Graph(identifier="urn:example:graph", store=store)

dataset = rdflib.Dataset(store=store)
dataset.add_graph(graph)

dataset.update("""
    insert data {
        graph ?g { <urn:example:subject> <urn:example:predicate> "another value"  }
    }
""", initBindings={
    "g": graph.identifier
})

print([ctx.identifier for ctx in dataset.contexts()])
print(graph.serialize())

The list of context identifiers printed is: [rdflib.term.Variable('g'), rdflib.term.URIRef('urn:example:graph'), rdflib.term.URIRef('urn:x-rdflib:default')]

So, instead of updated the graph "urn:example:graph", the sparql update has created a new graph with an identifier which is the variable g.

ghost commented 2 years ago

... instead of updated the graph "urn:example:graph", the sparql update has created a new graph with an identifier which is the variable g.

Yup, it's a bug, thanks for the report.