Repository navigation
Description
A Turtle insert takes <kb:n#x> without complaint, but upsert of the identical triple fails with a JSON-LD error. In Turtle, <…> is unambiguously an absolute IRI, so it seems the JSON-LD compact-IRI guard is firing on a round-trip it shouldn't be part of.
Repro (db main @ ac1e8a61b, fluree 4.2.1 built from it, local/direct mode):
fluree create iritest
fluree insert iritest '<kb:n#x> a <http://example.org/C> .'
# Committed t=1, 1 flakes
fluree upsert iritest '<kb:n#x> a <http://example.org/C> .'
# error: Transaction error: JSON-LD error: Unresolved compact IRI 'kb:n#x': prefix 'kb' is not defined in @context. If this is intended as an absolute IRI, use a full form (e.g. http://...) or add the prefix to @context.
fluree upsert iritest '<tag:example.org,2025:x> a <http://example.org/C> .'
# error: ... Unresolved compact IRI 'tag:example.org,2025:x': prefix 'tag' is not defined in @context. ...
fluree upsert iritest '<http://example.org/y> <http://example.org/rel> <kb:n#x> .'
# error: ... Unresolved compact IRI 'kb:n#x': prefix 'kb' is not defined in @context. ...
fluree upsert iritest '<urn:kb:x> a <http://example.org/C> .'
# Committed t=2, 1 flakes (urn: is allowlisted)Expected: the upserts behave like the insert.
Scope, from poking at it:
- Only default-graph triples are affected. The same IRI inside a TriG
GRAPH <urn:g:1> { … }block upserts fine, and so doesGRAPH <kb:graph> { … }. A body that mixes default-graph triples with a GRAPH block fails on the default-graph part. fluree sync(default graph) fails the same way.- Turtle
insertis unaffected.
Where. Claude traced the mechanism and checked these anchors at ac1e8a61b, fwiw:
fluree-db-api/src/tx.rs:3980-3983(upsert_turtle),:3998(upsert_turtle_with_opts),fluree-db-api/src/tx_builder.rs:463-474(builderInsertTurtle | UpsertTurtleafterparse_trig_phase1),fluree-db-api/src/tx.rs:2302(graph ops: sync / GSP) andfluree-db-cli/src/commands/graph_sync.rs:64all convert Turtle to JSON-LD withfluree_graph_turtle::parse_to_json(fluree-graph-turtle/src/lib.rs:60-65). That emits the IRIs as bare strings with no@context, then hands them to the JSON-LD transaction path.- JSON-LD expansion runs
guard_unresolved(fluree-graph-json-ld/src/expand.rs:113-124) →check_unresolved_iri(fluree-graph-json-ld/src/iri.rs:80-99). That accepts an unresolvedprefix:suffixonly when the suffix starts with//or the prefix is inKNOWN_SCHEMES(iri.rs:69-71: urn, did, mailto, tel, data, ipfs, ipns, geo, blob, magnet, fluree). Anything else isRejectLikelyCompact. insertdoesn't hit it becauseinsert_turtle→stage_turtle_insert(tx.rs:3717-3765) goes straight throughFlakeSink, with no JSON-LD round-trip.
For a JSON-LD body the guard makes total sense, because a bare "kb:n#x" string really is ambiguous there, and I'd leave JSON-LD behavior alone. The problem is only that Turtle's already-resolved IRIs pass back through it. RFC 3986 schemes aren't a closed set either (tag: is RFC 4151), so extending KNOWN_SCHEMES doesn't seem like the right lever.
Fix direction. Two options I can see:
- Minimally, let the Turtle→JSON callers opt out of the compact-IRI guard, e.g. an expansion option (or a marker from
parse_to_json) saying every IRI is already absolute. That would cover all five call sites above. - More fully, stop round-tripping Turtle through JSON-LD for upsert/sync and build the templates from the parsed graph, the way
stage_turtle_insertdoes for insert. It's more work, but it removes this whole class of "Turtle means X, JSON-LD reads it as Y" mismatch rather than patching the one we hit. I think it also saves a serialize/reparse on large Turtle upserts, though I haven't measured that.
Heads-up: #1971 (open, "Accept TriG on insert") adds stage_trig_insert, which also goes through parse_to_json(&phase1.turtle). So as written it would bring this to TriG insert too. It's probably worth deciding the direction before that lands.
Why it matters. We hit it with a customer's ontology export that carried a single property IRI with a private scheme (an unused leftover test attribute). The file loaded fine when the model was created, but updating the model from the same file, which is an upsert, then failed on the whole file. Any vocabulary that uses tag: or a private scheme hits the same wall, and once sync is the replace verb, so does syncing. The error message also sends people the wrong way ("add the prefix to @context"), since there's no @context anywhere in a Turtle payload.
The same code is at ffeeec554 (the rev fluree/solo pins). I couldn't find an existing issue for this. The nearby ones (#1280, #468) are about JSON-LD compaction and policy IRIs, not this.
Activity