Skip to content

Violation roots and values survive blank-node instances; messages come from the constraint's label - #3

Merged
namedgraph merged 3 commits into
masterfrom
fix-violation-roots-and-messages
Sep 21, 2026
Merged

namedgraph merged 3 commits into
masterfrom
fix-violation-roots-and-messages

Conversation

@namedgraph

Copy link
Copy Markdown
Member

Summary

Two fixes to SPINConstraints on Jena 6.1.0, plus tests.

Blank-node instances. QueryExecution.substitution() replaced initialBinding() in Jena 6 and rewrites the parsed query syntactically. When the checked instance is a blank node (an unsaved resource in a request body), the substituted ?this becomes a blank node written in the CONSTRUCT template, which template instantiation re-mints per solution. The violation root then denoted nothing in the checked model. Named instances were unaffected, because an IRI written in a template is a constant. See apache/jena#3267 for the Jena discussion; the fix follows the rewrite recommended there.

The parsed query is now rewritten once per constraint in createWrapper: the template's ?this is renamed to a fresh variable, and BIND(?this AS <fresh>) is appended to the WHERE group (and the variable added to GROUP BY where the query groups). The WHERE side still sees the substituted constant everywhere, filters included, and the template receives the instance as a variable value, which instantiation copies through unchanged in every position, the way the pre-Jena 6 initial binding did. The constraint's SPARQL text is not touched.

The first commit on this branch repaired spin:violationRoot after the fact by guessing which dangling blank root stood for the instance; the second commit replaces that heuristic and its instance parameter.

Messages. The violation message is the CONSTRUCT-emitted rdfs:label, else the caller-supplied label, else the constraint resource's own rdfs:label. No authored label means no message: the "SPIN constraint at ..." boilerplate is gone, and one violation's label no longer leaks into the next through the loop accumulator.

Tests

  • anonInstanceViolationRoot, anonInstanceViolationRootRDF: blank-node instance as root, in the returned violations and after addConstraintViolationsRDF.
  • anonInstanceViolationValue: blank-node instance emitted as both root and spin:violationValue. Fails against the heuristic, passes with the rewrite.
  • anonInstanceViolationRootWithThisUnderscoreInBody: the fresh variable does not collide with a body that already uses ?this_.
  • violationMessageFromConstraintLabel, violationMessageAbsentWithoutLabel, violationMessagesIndependentPerViolation.

mvn test: 52 tests, 0 failures.

🤖 Generated with Claude Code

namedgraph and others added 3 commits September 4, 2026 13:42
…the constraint's authored label.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WK1ssk2A67MYseeH3hWnhf
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WK1ssk2A67MYseeH3hWnhf
…lue, not as a written blank node.

substitution() rewrites the parsed query, so a blank node substituted for ?this becomes a blank node written in the template, which instantiation re-mints per solution; the violation root then denoted nothing in the checked model, and the previous fix repaired that one position after the fact by guessing which dangling blank root stood for the instance. Now the parsed query is rewritten once per constraint: the template's ?this becomes a fresh variable, bound from ?this by a BIND appended to the WHERE clause (and added to GROUP BY where the query groups). The WHERE side still sees the substituted constant everywhere, filters included, and the template copies the instance through unchanged in every position, as the pre-Jena 6 initial binding did. The constraint's SPARQL text is not touched, and the root-repair heuristic and its instance parameter are gone.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@namedgraph
namedgraph merged commit e4c3c3a into master Sep 21, 2026
@namedgraph
namedgraph deleted the fix-violation-roots-and-messages branch September 21, 2026 12:29
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

Successfully merging this pull request may close these issues.

1 participant