Skip to content

feat(shacl): consult f:classMembershipSource graphs for sh:class membership - #2204

Closed
mrpraneeth wants to merge 1 commit into
fluree:mainfrom
AGTx-com:feat/shacl-class-membership-source
Closed

mrpraneeth wants to merge 1 commit into
fluree:mainfrom
AGTx-com:feat/shacl-class-membership-source

Conversation

@mrpraneeth

Copy link
Copy Markdown
Contributor

Problem

sh:class resolves a value's rdf:type in the focus node's graph and the single f:shapesSource graph. That covers value-sets kept next to the shapes, but not a catalog kept in a named graph of its own. A common layout:

  • shapes in <…/shapes>;
  • records in per-tenant graphs (<…/org-a>, <…/org-b>, …);
  • the shared catalog they reference in <…/catalog>, with its own write permissions.

There, sh:class ex:Commodity on a record can never pass, because ex:coffee a ex:Commodity lives in neither consulted graph. f:shapesSource takes one graph selector, so the catalog can't be added there.

Change

f:classMembershipSource on f:shaclDefaults: a repeatable f:GraphRef whose graphs are added to the sh:class membership lookup.

<urn:config:shacl> f:shaclEnabled true ;
  f:shapesSource [ a f:GraphRef ; f:graphSource [ f:graphSelector <http://example.org/shapes> ] ] ;
  f:classMembershipSource [ a f:GraphRef ; f:graphSource [ f:graphSelector <http://example.org/catalog> ] ] .
  • Shapes: still compiled only from f:shapesSource. A membership graph only contributes rdf:type triples.
  • Validation of sources: f:shapesSource and the new setting now share one helper (resolve_shacl_graph_source). Both reject f:ledger, f:atT, f:trustPolicy and f:rollbackGuard, and an unknown graph fails with f:classMembershipSource graph '…' not found…, as f:shapesSource already does. The f:shapesSource error text is unchanged.
  • Both paths: the transaction path (tx.rs) and the standalone validate path (validate.rs) resolve the same membership graphs.
  • Cross-ledger: with a cross-ledger f:shapesSource, membership resolves against the model ledger, so the combination is rejected rather than silently ignored.
  • Config machinery:
    • field on ShaclDefaults, read with read_graph_source_refs;
    • merge: a non-empty list replaces the base;
    • registered as a config edge in config_vocab;
    • added to the documented repair recipe in writing-config.md.
  • Docs: setting-groups.md, override-control.md (non-overridable, like f:shapesSource), vocabulary.md, and a "Value-sets in their own graph" section in cookbook-shacl.md.

Tests

Written before the change. The first two new config-graph tests failed with Value coffee is not an instance of class Commodity, and the cross-ledger test failed with the same silent violation when the check was removed.

  • it_config_graph:
    • shacl_class_ignores_other_graphs_without_membership_source pins today's behavior;
    • shacl_class_membership_source_adds_a_catalog_graph: a member passes and a non-member is rejected;
    • shacl_class_membership_source_rejects_unknown_graph.
  • it_shapes_cross_ledger: cross_ledger_shapes_reject_class_membership_source.

Local results on main at 42bb964:

Check Result
cargo test -p fluree-db-api --features shacl --test grp_graphsource 329 passed
cargo test -p fluree-db-api --features shacl --lib 941 passed
cargo fmt --all --check clean
cargo clippy -p fluree-db-api -p fluree-db-core -p fluree-vocab --all-targets -- -D warnings clean

The full-workspace --all-features clippy is left to CI.

Context: we hit this in a ledger whose listings live in per-organization graphs and reference a shared catalog graph. We currently work around it by checking the type in a required write policy instead of sh:class.

🤖 Generated with Claude Code

…ership

sh:class looks up a value's rdf:type only in the focus node's graph and the
single f:shapesSource graph. A value-set or catalog kept in its own named
graph (neither the shapes graph nor the referencing data's graph) can never
satisfy sh:class, so data in many named graphs can't reference a shared
catalog graph.

f:classMembershipSource on f:shaclDefaults (repeatable f:GraphRef) adds
graphs to that lookup. Shapes are still compiled only from f:shapesSource.

- The same-ledger GraphRef checks are shared with f:shapesSource, so both
  reject f:ledger, f:atT, f:trustPolicy and f:rollbackGuard, and an unknown
  graph fails with "<setting> graph '…' not found".
- The transaction path and the standalone validate path resolve the same
  membership graphs.
- With a cross-ledger f:shapesSource, membership resolves against the model
  ledger, so the combination is rejected instead of silently ignored.
- Registered in config_vocab (config edge) and the documented repair recipe.
- Docs: setting groups, override control, vocabulary, SHACL cookbook.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@bplatz

bplatz commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Thank you for this. The use case is real, and this PR made it concrete.

Rather than a setting for sh:class alone, we've generalized it in #2264, which supersedes this PR. f:additionalDataSource reads the listed graphs together with the validated graph, as one graph, for every constraint. The catalog case works for sh:class, including subclass edges kept in the catalog. It also works for a property path into the catalog, sh:node checks on the referenced entry, cardinality, and sh:sparql. With a cross-ledger f:shapesSource it works too, since the local lookup runs before the model ledger is consulted, so that combination no longer needs to be rejected.

#2264 builds on the config plumbing and shared source resolution from this PR, and you're credited as co-author on its commit. Once it lands, the write-policy workaround you described should be replaceable with a plain sh:class constraint.

Closing in favour of #2264.

@bplatz bplatz closed this Nov 5, 2026
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.

4 participants