Repository navigation
Conversation
…ger view The graph operator decides what `GRAPH <iri>` reads, in a view of one ledger with no dataset, through three `ExecutionContext` methods that each re-derived the graph position and read the registry on their own. A datalog rule body is about to be checked against the same question before its rules run, and two copies of that answer would be free to drift: a body could be accepted for a name the operator reads as empty, or refused for one it reads. `single_ledger_graph` answers it once: the default graph (the ledger's own address, in any spelling), a user graph there as of `t`, a graph a later commit dropped (`GraphDropped`), or a name it reads no graph under, and why (`UnreadGraph`). The three methods now delegate to it. The operator calls them once per row, so the drop lookup stays behind `has_drops()`: a ledger that never dropped a graph does the same work as before, `graph_position` plus `visible_at`. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_018gr44QJuUPpGdwWfXE9Bz9
A rule body runs against one graph of one ledger, with no dataset and no graph-source reader. There, a `GRAPH <iri>` naming anything but a graph of that ledger yields no rows: SPARQL's answer for a graph outside the dataset, but a wrong one for a rule, because under a negation an empty input reads as "absent for everyone". A typo'd graph IRI, another ledger or a graph source in a body derived a full, plausible set of conclusions without a word. So did a default graph that merges several graphs (`from` naming two ledgers): a plain query reads them all, the rules read the first, and swapping the order changed the answer. Rule heads naming a missing graph were already refused; bodies were not, and the validator walked into `Pattern::Graph` without looking at its name. Before the rules run, a rule set is now refused, naming the rule and the graph, when a body names (at any depth: under a negation, in an EXISTS expression, a UNION branch or a subquery) a graph the ledger does not have as of the query's `t`, another ledger, a graph source, or a system graph, judged by the same table the graph operator reads by. `GRAPH ?g` and the ledger's own address are unchanged. A rule set over a default graph of several graphs is refused too; an empty rule set refuses nothing, so a ledger whose config enables datalog without rules answers as before. - The rule footprint records each constant graph a body names (`read_graphs`), from the walk stratification already does. - The check runs before the reasoning cache lookup: the cache key does not cover how many graphs the default graph merges, so a one-graph materialization would otherwise be served to a several-graph query. - `PrepareConfig` carries the query's graph-source reader, used only to say in the refusal that a name is a graph source. - The cross-ledger dataset test that ran rules over `from: [data, other]` now reads the second ledger as a named graph, and asserts the refusal. - Docs: what a body can read, including that a rule set written before its input graph has data fails until the graph exists; a compatibility entry. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_018gr44QJuUPpGdwWfXE9Bz9
A query that runs rules over a default graph of several ledgers is now refused, so pin down the supported way to compare what rules derive with another ledger: the rules run over the default graph alone, and the query reads the other ledger as a named graph of its dataset (`fromNamed` / `FROM NAMED`, `GRAPH`), both pinned with `@t:`, on both surfaces. The rule docs show the pattern beside the refusal. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_018gr44QJuUPpGdwWfXE9Bz9
bplatz
left a comment
There was a problem hiding this comment.
Approving. Please review the inline comments before merging.
Optional: the body defers the rules-over-every-member question to #2075; marking it Follow-up: #2075 (docs/contributing/issue-linking.md) makes the deferral linkable.
| QueryError::InvalidQuery(format!( | ||
| "this query's default graph merges several graphs, but datalog rules ({}) run over \ | ||
| one graph: they would read only ledger '{}' and derive as if the other graphs' \ | ||
| facts were absent. Run the rules over a default graph of one graph; a rule body can \ |
There was a problem hiding this comment.
This also fires when datalog comes from the first ledger's f:reasoningDefaults and the query never asked for reasoning, so every from: [this, other] query on a ledger with configured datalog and stored rules now fails, including ones that read no derived predicate. Where f:overrideControl denies overrides, the query can't opt out at all. Could the message name the way out ("reasoning": "none" where overrides are allowed, or reading the other ledgers through fromNamed, as the new docs example does), and the compatibility entry call out the configured-reasoning case?
| if rule_set.is_empty() { | ||
| return Ok(()); | ||
| } | ||
| if scope.multi_default_graph { |
There was a problem hiding this comment.
multi_default_graph is false when the dataset has no default graph at all (fromNamed / FROM NAMED only). DataSetDb::primary() then falls back to the first named graph, so the rules run over that one graph as if it were the default graph, the same one-of-several answer this refuses for from: [a, b]. Should a rule set over an empty default graph be refused too, or does something else already stop it?
| graph. `GRAPH ?g { … }` ranges over the ledger's named graphs. | ||
|
|
||
| A body naming anything else fails the query, naming the rule and the graph: | ||
| a graph the ledger does not have as of `t` (a typo'd IRI, say), another |
There was a problem hiding this comment.
Optional: "does not have as of t" is stronger than the check. The registry also holds graphs first written after t (visible_at only looks at drops), so a query at a t before the graph's first write accepts the body and reads the graph as empty, while the same rule at the head before the graph exists is refused. Either word it as "a graph the ledger has never had, or has dropped by t", or note the time-travel case. Same wording at line 348 and in compatibility.md.
| let base = GraphDbRef::new(db_ref.snapshot, db_ref.g_id, overlay, db_ref.t); | ||
| let graph_sources = crate::r2rml_provider!(self); | ||
| let inputs = RuleInputScope { | ||
| multi_default_graph: super::union_default_dataset(db, &executable) |
There was a problem hiding this comment.
Optional: this re-derives the several-graphs test by hand, while the query paths take planning.multi_default_graph from PlanningContext::with_dataset_scope, whose docs make it the one definition. PlanningContext::current().with_dataset_scope(union.as_ref()).multi_default_graph keeps explain and query from disagreeing if that definition changes.
… ledger in fromNamed The dataset cases of the_tally_names_the_data_commit_the_rules_ran_over ran datalog rules over `from: [data, other]`, a default graph of two ledgers. #2463 refuses that shape (rules run over one graph), so the test would fail whichever of the two lands second. The other ledger is now a named graph, the shape both accept, and the query still goes through the dataset path, so "for a dataset it names the primary ledger" is still what it checks. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_018gr44QJuUPpGdwWfXE9Bz9
Fixes #2459
Problem
A datalog rule body runs against one graph of one ledger, with no dataset and no graph-source reader. In that context a
GRAPH <iri>naming anything other than a graph of that ledger yields no rows, which is SPARQL's answer for a graph outside the dataset but a wrong one for a rule: under a negation an empty input reads as "absent for everyone". So a typo'd graph IRI, another ledger, or a graph source in a body derived a full, plausible set of conclusions, silently. The same happened over a default graph that merges several graphs ("from": ["data:main", "other:main"]): a plain query joins across both, while the rules read only the first and conclude as if the others' facts were absent. Swap the order and the answer changes.A rule head naming a missing graph was already refused (
HeadGraphs::resolve); bodies had no counterpart, and the validator walked intoPattern::Graphwithout looking at its name.What changed
t, another ledger ('other:main'), a graph source, or a system graph. The check covers every constantGRAPHin a body, at any depth: undernot-exists/FILTER NOT EXISTS, in anEXISTSexpression, aUNIONbranch, a subquery, and aGRAPHwhose group reads no fact.GRAPH ?gis unchanged, and the ledger's own address (any spelling) still reads its default graph. A graph a commit aftertdropped fails as the graph operator already fails it (GraphDropped, 404).from, twoFROMclauses, or two graphs of one ledger), rather than answering over the first graph only. An empty rule set refuses nothing, so a ledger whose config turns datalog on but holds no rules answers multi-ledger queries as before. Whether rules should read every member stays on Scopes of several graphs: a one-graph witness type, and the readers that still read one graph #2075.GRAPH <iri>reads in a single-ledger view.single_ledger_graph(fluree-db-query/src/context.rs) now backs both the graph operator'ssingle_db_user_graph_id/single_db_names_default_graph/refuse_dropped_graphand the rule check, so a body is accepted exactly when the operator would read the graph it names. The no-drops path does the same work as before (graph_position+visible_at, plus onehas_drops()check).RuleFootprint::read_graphs), from the walk the stratification analysis already does, rather than a second walk.PrepareConfigcarries the query's graph-source reader (with_graph_sources), used only to label a refused name as a graph source; the refusal itself does not depend on it.docs/query/datalog-rules.md(the graph-source bullet was true only for the pattern kinds the validator sees; new "What a body can read" section, including that a rule set written before its input graph has data fails until the graph exists), and a breaking-change entry indocs/reference/compatibility.md.Breaking changes
f:rulesSource, or query-time) now fails with a 400 instead of running them over the first graph.it_rules_cross_ledger::dataset_query_pulls_rules_from_model_ledgerpinned the old behavior overfrom: [data, other]; it now reads the second ledger as a named graph (the same multi-ledger dataset path) and asserts the refusal for the two-member default graph.Tests
fluree-db-api/tests/it_datalog_body_graphs.rs(ingrp_reasoning), on the issue's fixture extended so every case answers differently (an exclusion indata's default graph, in itsex:exclusionsgraph, and inother's default graph):GRAPH <ex:exclusions>, the ledger's own address, andGRAPH ?gderive the right candidates;<ex:exclusionz>, another ledger (pure address and IRI/address ambiguous spellings) andtxn-metaare refused with a 400 naming the rule and the graph;graph,union,querysubquery, agraphholding only abind; SPARQLFILTER NOT EXISTS,!EXISTS,UNION, sub-SELECT); a stored rule on the SPARQL query surface;from: [data, other],[other, data]and[data, data#exclusions]with rules are refused, after a one-graph query has cached its materialization; with no rules the multi-ledger datalog query answers as before; SPARQLFROM/FROMtwin with stored rules in both orders.it_iceberg_local_fs::a_rule_body_naming_a_graph_source_is_refused: a registered R2RML source (and an unmapped one) named in a rule body is refused with the graph-source message, on the ledger path and with the source in the dataset'sfromNamed, for JSON-LD and SPARQL rules, while the sameGRAPHin a plain dataset query reads the source's rows.Non-vacuity, each mutation committed-then-restored: skipping the body-graph loop fails the five body-graph tests and the graph-source test (the three others pass); disabling the several-graphs refusal fails exactly the two several-graphs tests; moving the check after the cache lookup fails
rules_over_a_default_graph_of_several_graphs_are_refused(the cached one-graph answer is served).The issue's repro, on a CLI built from this branch (and on the v4.2.4 CLI, where
<…exclusionz>andother:maineach answered alice and bob):<…exclusions>still derives bob only;<…exclusionz>andother:mainfail naming the rule and the graph. Over HTTP (fluree server run,POST /v1/fluree/query/data:main) those two are 400err:db/InvalidQuery, and so isfrom: ["data:main", "other:main"]with the rule.Suites run locally, all green:
grp_reasoning285,it_reasoning_lane_cache2,grp_query_reason106,grp_graphsource283,grp_ledger311 (the graph-drop tests the shared classifier now serves),grp_query614 (1 ignored),grp_query_sparql578 (3 ignored),fluree-db-querylib 1861 (2 ignored),it_iceberg_local_fs54; re-run after mergingorigin/mainfor the ones this touches.cargo clippy -p fluree-db-query -p fluree-db-api --all-features --all-targets --no-deps -- -D warningsis clean. The workspace-wide gate is CI's.Performance: the graph operator asks the shared classifier once per row; on a ledger that never dropped a graph it does what it did before (
graph_position+visible_at) plus onehas_drops(). The rule check runs once per reasoning query with a non-empty rule set, one registry lookup per constant body graph, ahead of materialization.Remaining / out of scope
FROM <other> FROM <data>and rules stored indataalone, there is nothing to run and nothing is refused. That is the "should rules see every member" decision on Scopes of several graphs: a one-graph witness type, and the readers that still read one graph #2075.GRAPH ?gwhose?gaVALUESbinds to a name the ledger does not have still yields no rows, as SPARQL specifies for a variable graph.🤖 Generated with Claude Code
https://claude.ai/code/session_018gr44QJuUPpGdwWfXE9Bz9