Violation roots and values survive blank-node instances; messages come from the constraint's label - #3
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two fixes to
SPINConstraintson Jena 6.1.0, plus tests.Blank-node instances.
QueryExecution.substitution()replacedinitialBinding()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?thisbecomes 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?thisis renamed to a fresh variable, andBIND(?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:violationRootafter the fact by guessing which dangling blank root stood for the instance; the second commit replaces that heuristic and itsinstanceparameter.Messages. The violation message is the CONSTRUCT-emitted
rdfs:label, else the caller-supplied label, else the constraint resource's ownrdfs: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 afteraddConstraintViolationsRDF.anonInstanceViolationValue: blank-node instance emitted as both root andspin: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