Skip to content

Node-level @graph does not reach nested nodes: the documented JSON-LD config disables SHACL #1979

Closed

Description

@aaj3f

Verified at origin/main 0c5d32c11 (fluree 4.2.1) on 2026-09-28, and reconfirmed side by side
against 6b63e64b3 (fluree 4.2.0), 261 commits earlier, on the same machine. Behaviour is identical
at both revs. fluree/solo currently pins ffeeec554, which sits between them (231 commits past
6b63e64b3, 30 behind 0c5d32c11); parse/jsonld.rs, config_resolver.rs,
fluree-graph-turtle/src/parser.rs and docs/ledger-config/writing-config.md are byte-identical
between ffeeec554 and 0c5d32c11, so the repro below is both what a maintainer reproduces and what
the product ships.

Scope. This is the JSON-LD parse half only: triples that never receive a graph. The separate
symptom of an export dropping a graph the triples do carry is #1847 (open; see Related — its silent
form no longer reproduces at 0c5d32c11).

Summary

In JSON-LD transactions, "@graph": "<iri>" on a node object scopes that node's own triples to the
named graph but not the triples of any object nested under it. Nested nodes are parsed by a recursive
call that re-reads @graph from the nested object, which does not have one, so their triples are
emitted untagged and land in the default graph. The write is accepted with a real commit id and a
real t.

For a f:LedgerConfig the result is not a no-op but an inversion. A ledger with shapes and no
config at all
validates writes against those shapes. Writing the config the docs prescribe —
f:shaclEnabled true, f:validationMode f:ValidationReject — leaves a f:shaclDefaults reference
pointing at a blank node whose properties are outside the config graph, so the reader finds the group
present and every field unset, and merge_shacl_opts defaults enabled to false. Asking for
enforcement turns enforcement off, with no error on any channel.

Steps to reproduce

Run at 0c5d32c11 (fluree 4.2.1), local CLI, no server, in an empty directory.

fluree init
fluree create govdemo

Shapes into the default graph:

cat > shapes.jsonld <<'EOF'
{ "@context": { "sh": "http://www.w3.org/ns/shacl#", "cm": "http://example.org/cm#" },
  "@graph": [ { "@id": "cm:RequirementShape", "@type": "sh:NodeShape",
      "sh:targetClass": { "@id": "cm:Requirement" },
      "sh:property": [
        { "@id": "cm:propActor",   "sh:path": { "@id": "cm:actor" },         "sh:minCount": 1 },
        { "@id": "cm:propControl", "sh:path": { "@id": "cm:mappedControl" }, "sh:minCount": 1 } ] } ] }
EOF
fluree insert govdemo -f shapes.jsonld      # Committed t=1, 8 flakes

The config, in the shape docs/ledger-config/writing-config.md prescribes — node-level @graph,
settings nested as anonymous objects:

cat > config-nested.jsonld <<'EOF'
{ "@context": { "f": "https://ns.flur.ee/db#" },
  "@graph": [
    { "@id": "urn:fluree:govdemo:main:config:ledger",
      "@type": "f:LedgerConfig",
      "@graph": "urn:fluree:govdemo:main#config",
      "f:shaclDefaults": {
        "f:shaclEnabled": true,
        "f:validationMode": { "@id": "f:ValidationReject" },
        "f:shapesSource": { "@type": "f:GraphRef",
          "f:graphSource": { "f:ledger": "govdemo:main",
                             "f:graphSelector": { "@id": "f:defaultGraph" } } } } } ] }
EOF
fluree insert govdemo -f config-nested.jsonld    # Committed t=2, 9 flakes

Then write a record the shapes forbid:

cat > bad-record.jsonld <<'EOF'
{ "@context": { "cm": "http://example.org/cm#" },
  "@id": "cm:REQ-BAD-001", "@type": "cm:Requirement",
  "cm:title": "missing actor and mappedControl" }
EOF
fluree insert govdemo -f bad-record.jsonld

Expected

Either the nine triples of the config document all land in urn:fluree:govdemo:main#config, or the
document is refused. A f:LedgerConfig whose f:shaclDefaults does not resolve inside the config
graph is not a config — and it must not be worse than writing no config at all.

Actual

The config write is accepted:

Committed t=2, 9 flakes

The forbidden record is also accepted — nothing enforces:

Committed t=3, 2 flakes

Decoding the config commit shows where the nine triples went. Flakes 7 and 8 — the f:LedgerConfig
node's own two triples — carry a graph; flakes 0 through 6 — every nested setting — carry none:

fluree show -l govdemo <commit>      # commit id from `fluree log govdemo`
0 ['_:fdb-…-b0', 'f#shaclEnabled',   True,                  xsd:boolean, True]
1 ['_:fdb-…-b0', 'f#shapesSource',   '_:fdb-…-b1',          '@id', True]
2 ['_:fdb-…-b0', 'f#validationMode', 'f#ValidationReject',  '@id', True]
3 ['_:fdb-…-b1', 'rdf#type',         'f#GraphRef',          '@id', True]
4 ['_:fdb-…-b1', 'f#graphSource',    '_:fdb-…-b2',          '@id', True]
5 ['_:fdb-…-b2', 'f#graphSelector',  'f#defaultGraph',      '@id', True]
6 ['_:fdb-…-b2', 'f#ledger',         'govdemo:main',        xsd:string, True]
7 ['urn:fluree:govdemo:main:config:ledger', 'rdf#type',        'f#LedgerConfig',
     '@id', True, {'graph': 'urn:fluree:govdemo:main#config'}]
8 ['urn:fluree:govdemo:main:config:ledger', 'f#shaclDefaults', '_:fdb-…-b0',
     '@id', True, {'graph': 'urn:fluree:govdemo:main#config'}]

Reading the config graph back confirms it holds two triples:

fluree query govdemo --sparql --format table \
  -e 'SELECT ?s ?p ?o FROM <urn:fluree:govdemo:main#config> WHERE { ?s ?p ?o }'
urn:fluree:govdemo:main:config:ledger  rdf:type            f:LedgerConfig
urn:fluree:govdemo:main:config:ledger  f:shaclDefaults     fdb-…-b0
(2 rows)

So the config graph holds a type and a f:shaclDefaults pointing at a blank node that has no
properties in that graph. The chain is severed at the first nesting. The seven settings triples are
in the default graph, alongside the user's own data. That is visible in an export, and the export is
behaving correctly — it is serializing what the writer wrote. fluree export govdemo emits the seven
as three free-floating blank nodes in the default graph; fluree export govdemo --all-graphs --system-graphs --format trig emits a dataset whose f:shaclDefaults sits in one graph and points at
a blank node defined in another, which is not a round-trippable RDF dataset. Nothing here is an export
defect — the export-side defect is #1847, and its silent form no longer reproduces at 0c5d32c11
(--format trig now warns "1 named graph not exported; pass --all-graphs to include it", and
--all-graphs emits it).

Three controls, same binary, same shapes, same forbidden record

No config at all still enforces. A ledger with only shapes.jsonld refuses the same record:

error: Transaction error: SHACL validation failed with 2 violation(s):
  1. Expected at least 1 value(s) but found 0
     Focus node: cm:REQ-BAD-004
     Path: cm:actor
     Constraint: http://www.w3.org/ns/shacl#MinCountConstraintComponent
  2. …Path: cm:mappedControl…

This is the control that matters: the documented JSON-LD config does not fail to add enforcement, it
removes enforcement that was there without it.

The same document with an explicit @id and its own @graph on every nested node commits the
same nine flakes and enforces.

The same config written with SPARQL INSERT DATA and a GRAPH clause — the route the same docs
page prescribes at :39-52 — keeps the whole chain, blank node included:

fluree update govsparql -f config.ru --format sparql   # Committed t=2, 4 flakes
fdb-…-#bnpl0                            f:shaclEnabled     true
fdb-…-#bnpl0                            f:validationMode   f:ValidationReject
urn:fluree:govsparql:main:config:ledger  rdf:type          f:LedgerConfig
urn:fluree:govsparql:main:config:ledger  f:shaclDefaults   fdb-…-#bnpl0
(4 rows)

and the forbidden record is refused. So blank nodes are not the problem, the config graph is not the
problem, and the reader is not the problem. The JSON-LD writer's handling of a node-level @graph
is. The docs' own four-triple JSON-LD snippet (writing-config.md:81-96), run against the same
shapes, splits the same way: 4 flakes committed, 2 in the config graph, f:shaclEnabled and
f:validationMode left in the default graph, forbidden record commits.

Root cause

fluree-db-transact/src/parse/jsonld.rs, in parse_expanded_object_with_ctx (:1347):

  • :1364 reads the node-level @graph, :1379 interns it through ctx.write_graphs.get_or_assign,
    and :1381 falls back to ctx.default_graph. The result is a local node_graph binding. It is
    never written back into ctx.
  • :1446 recurses into each property value —
    parse_expanded_objects_with_ctx(value, ctx, &mut templates) — passing ctx but not node_graph.
    Nested node objects re-enter parse_expanded_object_with_ctx at :1616 (nested node with @id)
    and :1678 (anonymous node), where :1364 finds no @graph on the nested object and :1381
    falls back to ctx.default_graph, which is None. Their templates are appended untagged at
    :1617 / :1679.
  • :1419-1420 and :1451-1452 then tag the parent node's own @type and property triples with
    node_graph — the only two triples that get scoped.
  • ctx.default_graph (:858) is written in exactly one place: :968-970, the update-template
    sugar ["graph", <iri>, <pattern>], which replaces it, parses the body, and restores the previous
    value. The insert and upsert paths construct the context with default_graph: None (:291,
    :347) and never set it, so on those paths a node-level @graph is the only way to address a
    named graph and it cannot reach a nested node.

The right shape is already in the same file. parse_graph_insert (:198) — the request-level target
graph, used by parse_sync_transaction (:183) and fluree-db-api/src/tx.rs:2334 — re-homes every
template in the transaction, nested ones included:

// :224-226
for t in &mut txn.insert_templates {
    t.graph = TemplateGraph::Iri(Arc::clone(&target));
}

Node-level @graph is the one graph-addressing path that tags a node rather than a subtree.

The reader is consistent and does its job: fluree-db-api/src/config_resolver.rs resolves every
config field against CONFIG_GRAPH_ID — find_instances_of_type at :797 and
query_config_predicate at :818, which builds GraphDbRef::new(snapshot, CONFIG_GRAPH_ID, overlay, to_t) at :834. It looks only in the config graph, which holds only the severed head of the chain.
read_shacl_defaults (:1148) therefore returns Some(ShaclDefaults) with every field None, and
merge_shacl_opts (:510) turns that into enabled: shacl.enabled.unwrap_or(false) (:540) — the
inversion. The comment at :536-539 explains the false default as the safer posture, which it is
for a config the user wrote; it is the wrong outcome for a config the user wrote and the writer lost.

Impact

docs/ledger-config/writing-config.md prescribes the failing shape, and is unchanged at
0c5d32c11. The "Writing via JSON-LD" section (:77-96) is the document reproduced above — node-level
@graph, f:shaclDefaults as a nested anonymous object — and :54 says "The JSON-LD form below works
with fluree insert unchanged." A config written the documented way, through the documented command,
disables the enforcement the ledger had before it.

The same page's SPARQL route (:39-52) works. So the page ships a working recipe and a broken one,
four lines apart, with a sentence in between promising the broken one works.

The same mechanism applies to any config group resolved out of the config graph —
f:policyDefaults, f:reasoningDefaults, f:datalogDefaults — and to any user document that nests
nodes under a node-level @graph, where the effect is quieter still: the nested triples are written
into the default graph and become indistinguishable from data.

A config is a bad place for a silent failure, because its whole job is to be believed later. A write
that fails loudly gets retried; a write that succeeds and does nothing gets depended on. A write that
succeeds and quietly disables the thing it asked for is worse than either.

Proposed fix

  1. Nested nodes inherit the enclosing node's @graph. In parse_expanded_object_with_ctx, set
    ctx.default_graph = node_graph.clone() around the property loop and restore it afterwards — the
    same save/parse/restore the update-template wrapper already does at :968-970. A nested node that
    carries its own @graph still wins, because :1364 is read before the :1381 fallback. The
    restore has to survive the ? returns inside the loop (a guard, or hoisting the loop into a
    helper), not just the happy path. Nothing else on the insert/upsert paths is affected, because
    they construct the context with default_graph: None (:291, :347). parse_graph_insert's
    whole-subtree re-home at :224-226 is the semantics to match.

  2. Fix the docs either way. writing-config.md:54 must stop promising the JSON-LD form works, and
    :77-96 must either go or show every node in the chain with its own @id and @graph. The
    working SPARQL recipe is already on the page.

  3. Name blank nodes in the TriG parse errors. A blank node inside a GRAPH block is refused with
    a message that names the token, not the construct. Two lines each:

    • GRAPH <urn:g> { [ f:shaclEnabled true ] . } → Parse error: expected subject, found '['
    • GRAPH <urn:g> { <urn:a> f:shaclDefaults [ f:shaclEnabled true ] . } →
      Parse error: expected object, found '['

    The same blank nodes outside a GRAPH block commit fine, so the construct, not the syntax, is
    what is unsupported — and neither message says so, which makes the fix (give every node an IRI)
    undiscoverable from the error. A GRAPH block nested inside a GRAPH block produces
    expected subject, found 'GRAPH', and so does TriG fed to fluree insert, which routes to the
    streaming Turtle parser (fluree insert -f g.ttl on a single GRAPH block: Turtle parse error: Parse error at position 38: expected subject, found 'GRAPH'). A single GRAPH block through
    upsert does not error — the non-streaming parser reads it and places the graph — so the trap is
    insert-specific, not "TriG through the Turtle parser". The string is pinned as a documented trap in
    fluree-graph-turtle/src/parser.rs:2532, fluree-db-api/tests/it_reserved_graph_writes.rs:120
    and docs/transactions/turtle.md:513. All four messages come from
    fluree-graph-turtle/src/parser.rs:819 / :1031, which format the token kind and nothing else.

    Reaching any of them now needs --format turtle: at 0c5d32c11 a .trig file is refused up front
    by fluree-db-cli/src/detect.rs:94 ("'trig' is a dataset format and carries named graphs, which
    insert cannot place"), where at 6b63e64b3 fluree upsert -f config.trig committed the file. The
    refusal's help points at fluree create <ledger> --from <file>.trig, which cannot add config to a
    ledger that already exists; fluree upsert -f config.trig --format turtle still works and places
    the named graph correctly. docs/transactions/turtle.md:513 still says "Named-graph blocks are
    read by fluree upsert -f file.trig", which the extension check now refuses — worth a separate
    look, but it means the TriG workaround this issue's readers will reach for is no longer the one
    the docs describe.

If (1) is judged too large a semantic change — "@graph": "<iri>" as a string-valued key inside a
node object is a Fluree extension, not JSON-LD 1.1, where @graph takes a node or array of nodes —
then the alternative is to refuse a node that carries @graph and has a nested node object without
one, rather than accept a partial write. What should not stay is the current outcome, where the
document is accepted, two of its nine triples are honored, and the ledger ends up less governed than
if the document had never been sent.

Related

  • 3b8136c8d "fix: route named graphs by ledger graph id, not transaction-local numbers" (bplatz,
    2026-09-24) — same family, does not fix this. It deleted GraphIdAssigner and the
    default_graph_id field, so templates now carry the graph IRI (TemplateGraph) and transactions
    carry Txn::write_graphs; its own commit message lists "SHACL validated staged subjects against
    that same wrong graph … so JSON-LD writes to named graphs (local 2 = #config) were effectively
    never validated" as one of the bugs it closes. That was the routing of the graph a template
    already carried. This defect is one level earlier: the nested templates never get a graph at all,
    so there is nothing to route. The rename Option<u64> → Option<Arc<str>> moved the mechanism
    without changing it — :1381 still falls back to a ctx field that only the update-template
    wrapper ever sets. Empirically identical before and after: 9 flakes, 2 scoped, forbidden record
    commits, at both 6b63e64b3 and 0c5d32c11.
  • 5abd39033 "fix(transact): a written graph missing from the registry fails the commit" — follow-up
    to the above; makes an unresolvable written graph IRI an error instead of a silent drop. Does not
    reach this case, because a template with no graph is not an unresolvable graph.
  • fluree-db-api/tests/it_config_graph.rs gained 154 lines in 3b8136c8d, including a test named
    config_write_json_ld. It writes TriG. Every config-write test in that file writes TriG with an
    explicit IRI on every node, which is the shape that works; the nested-anonymous-object JSON-LD
    shape the docs prescribe is not covered.
  • fluree export --format trig / --format nquads omit named graphs entirely #1847 (open) — fluree export --format trig / --format nquads omit named graphs. Different
    end of the pipe and deliberately out of scope here: that one is triples that have a graph and lose
    it on the way out, this one is triples that never get a graph on the way in. Its silent form is gone
    at 0c5d32c11 — the export warns and --all-graphs carries the graph — so what is left of it is
    the opt-in default, not data loss. Kept separate for that reason; if a maintainer reads the two as
    one defect, this is the half that lives in parse/jsonld.rs.
  • security: f:policySource enforced on reads but ignored on writes (modify paths hardcode default graph) #1416 (closed) — f:policySource enforced on reads but ignored on writes (modify paths hardcode the
    default graph). Closest neighbour: a config-graph setting that silently fails to take effect.
    Different mechanism — that one is the write path hardcoding g_id = 0, this one is the parser not
    propagating a node-level @graph into nested nodes.
  • Ledger-configured f:defaultAllow false does not apply to requests carrying no policy inputs (and reads/writes disagree) #1640 (closed) — ledger-configured f:defaultAllow false not applying to requests carrying no
    policy inputs. The other shape of "the config graph was read and still did not govern", reached
    through gate ordering rather than graph scoping. Worth reading beside this one because it poses the
    same question directly: whether a ledger's own declared posture should be escapable — there by a
    request that says nothing, here by a JSON-LD spelling.
  • Branch merge/rebase/revert commit without SHACL validation — a merge silently writes state the ledger's own shapes reject #1782 (closed) / Validate SHACL rules on merge operations #1822 (merged) — merge/rebase/revert committing without SHACL validation. Shares the
    symptom (a ledger ends up in a state its own shapes reject, silently) but not the cause; Validate SHACL rules on merge operations #1822 fixed
    that path.
  • Bulk TriG import persists reserved-graph triples into an unreachable graph id #1846 (closed) — bulk TriG import persists reserved-graph triples into an unreachable graph id.
    Adjacent: also triples that are committed but not where the reader looks, on the TriG import path
    rather than the JSON-LD one.
  • The API-side symptom is written up separately in a solo draft (issue-solo-success-for-a-noop.md,
    item 4): the transaction routes return the engine's commit envelope verbatim, so status: success
    with a t is a statement about the commit and never about whether the config was ingested.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FKfvWbLpzNkhC4eGvHXN1F

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions