grafeo icon indicating copy to clipboard operation
grafeo copied to clipboard

SPARQL named-graph DELETE/INSERT WHERE is silently broken (wrong-graph writes, no-op deletes, lost on replay)

Open teipsum opened this issue 5 months ago • 1 comments

Summary

Several SPARQL 1.1 Update operations that target a named graph through a pattern or a DELETE/INSERT ... WHERE (MODIFY) parse, execute, and report success while doing the wrong thing — with no error or warning. The most serious case is silent data corruption: an INSERT ... WHERE whose template is wrapped in a GRAPH block writes into the default graph instead of the named one.

By contrast, the concrete-term forms (INSERT DATA, DELETE DATA) and DROP GRAPH work correctly on named graphs, so the problem is specific to the pattern/MODIFY mutation path.

Reproduced on 0.5.42 (and present back through 0.5.40).

1. Silent mis-write: named INSERT-via-MODIFY lands in the default graph

A GRAPH-wrapped INSERT template is written to the default graph rather than the named graph, and the call reports success.

# seed something so the WHERE binds one row
INSERT DATA { <http://example.org/trigger> <http://example.org/p> "go" . }

# intends to insert into graph <http://example.org/g>
INSERT { GRAPH <http://example.org/g> { <http://example.org/s> <http://example.org/p> "v" } }
WHERE  { <http://example.org/trigger> <http://example.org/p> ?x }
# the named graph is empty ...
SELECT ?s WHERE { GRAPH <http://example.org/g> { ?s <http://example.org/p> "v" } }   # 0 rows

# ... and the triple silently landed in the default graph instead
SELECT ?s WHERE { ?s <http://example.org/p> "v" }                                    # 1 row

Expected: the triple is inserted into <http://example.org/g>; the default graph is untouched. Actual: the triple is inserted into the default graph; the named graph is empty; no error.

The same mis-write happens for a WITH <g> INSERT { ... } WHERE { ... }.

2. Silent no-op: named DELETE WHERE deletes nothing

INSERT DATA {
  GRAPH <http://example.org/g> {
    <http://example.org/a> <http://example.org/p> "1" .
    <http://example.org/b> <http://example.org/p> "2" .
  }
}

DELETE WHERE { GRAPH <http://example.org/g> { <http://example.org/a> <http://example.org/p> "1" } }

SELECT ?s WHERE { GRAPH <http://example.org/g> { ?s <http://example.org/p> ?o } }

Expected: <http://example.org/a> is removed; one row (b) remains. Actual: nothing is removed; both rows remain; no error.

The GRAPH-wrapped DELETE/INSERT MODIFY form has both faults at once: the delete no-ops and the insert mis-writes into the default graph.

3. Read-side: a WITH-scoped MODIFY with an unqualified WHERE binds nothing

INSERT DATA {
  GRAPH <http://example.org/g> { <http://example.org/alix> <http://example.org/status> "active" . }
}

WITH <http://example.org/g>
DELETE { <http://example.org/alix> <http://example.org/status> ?s }
INSERT { <http://example.org/alix> <http://example.org/status> "archived" }
WHERE  { <http://example.org/alix> <http://example.org/status> ?s }

SELECT ?s WHERE { GRAPH <http://example.org/g> { <http://example.org/alix> <http://example.org/status> ?s } }

Expected: WITH <g> makes the unqualified WHERE read from <g>, so the match binds and the status becomes "archived". Actual: the WHERE is evaluated against the (empty) default graph, binds zero rows, and the whole MODIFY is a no-op; the status stays "active".

4. Durability: a MODIFY is lost on reopen

Independently of named graphs, a DELETE/INSERT ... WHERE MODIFY emits no write-ahead-log record at all, so under wal-directory storage the mutation is applied in memory but does not survive a close/reopen replay (this also affects the default graph).

Unsupported variants should fail loudly, not silently

USING / USING NAMED and a variable graph target (GRAPH ?g in a DELETE/INSERT template) are currently accepted and then silently dropped / mis-routed. For operations that change data, silently doing nothing (or the wrong thing) is worse than refusing; these would ideally raise an explicit error until implemented.

Spec references

  • SPARQL 1.1 Update, 3.1.3 DELETE WHERE — the GRAPH-wrapped form must delete from the named graph.
  • SPARQL 1.1 Update, 3.1.5 DELETE/INSERT (MODIFY), including the WITH and USING clauses — named-graph targeting and the WITH default-graph redefinition.

Environment

  • grafeo 0.5.42
  • Model: RDF / SPARQL
  • Storage: in-memory for the routing cases; wal-directory for the durability case.

A PR with a fix and regression tests follows.

teipsum avatar Jun 11 '26 20:06 teipsum

Fixed and tested in 0.5.43

StevenBtw avatar Sep 27 '26 18:09 StevenBtw