Skip to content

Commit

Permalink
Merge pull request #600 from joernhees/fix_query_update_initns
Browse files Browse the repository at this point in the history
Graph.update() uses own namespaces if none given, fixes #579
  • Loading branch information
joernhees committed Feb 16, 2016
2 parents 39cb1bc + 656a483 commit 58d635b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
8 changes: 5 additions & 3 deletions rdflib/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -1084,10 +1084,12 @@ def query(self, query_object, processor='sparql',
query_object, initBindings, initNs, **kwargs))

def update(self, update_object, processor='sparql',
initNs={}, initBindings={},
initNs=None, initBindings=None,
use_store_provided=True, **kwargs):
"""
"""
"""Update this graph with the given update query."""
initBindings = initBindings or {}
initNs = initNs or dict(self.namespaces())

if hasattr(self.store, "update") and use_store_provided:
try:
return self.store.update(
Expand Down
16 changes: 16 additions & 0 deletions test/test_issue579.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# test for https://github.com/RDFLib/rdflib/issues/579

from rdflib import Graph, URIRef, Literal, Namespace
from rdflib.namespace import FOAF, RDF

g = Graph()
g.bind('foaf', FOAF)
n = Namespace("http://myname/")
g.add((n.bob, FOAF.name, Literal('bb')))
# query is successful.
assert len(g.query("select ?n where { ?n foaf:name 'bb' . }")) == 1
# update is not.
g.update("delete where { ?e foaf:name 'ss' .}")
assert len(g) == 1
g.update("delete where { ?e foaf:name 'bb' .}")
assert len(g) == 0

0 comments on commit 58d635b

Please sign in to comment.