From 7a70d50409a3469fd764f1f83b9540d41709678b Mon Sep 17 00:00:00 2001 From: hari2353 <125888547+hari2353@users.noreply.github.com> Date: Wed, 11 Nov 2026 00:36:52 +0530 Subject: [PATCH] fix: #1447 decide writes via bound_plan::write::is_write_statement (clause-list only) --- clickgraph-embedded/src/connection.rs | 2 +- src/bound_plan/write.rs | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/clickgraph-embedded/src/connection.rs b/clickgraph-embedded/src/connection.rs index be1ff5435..ef73f17ce 100644 --- a/clickgraph-embedded/src/connection.rs +++ b/clickgraph-embedded/src/connection.rs @@ -1317,7 +1317,7 @@ impl<'db> Connection<'db> { // in any arm enters the write pipeline, which executes it or refuses // it clearly (a write in a UNION: "an updating clause in a UNION"); // the read path would answer "ClickGraph is read-only". - if prepared.targets.is_write() { + if clickgraph::bound_plan::write::is_write_statement(text) { return self.handle_write_async(text).await; } self.query_with_executor_async(text, &self.executor).await diff --git a/src/bound_plan/write.rs b/src/bound_plan/write.rs index 9ea1b81b5..e2d375bc5 100644 --- a/src/bound_plan/write.rs +++ b/src/bound_plan/write.rs @@ -64,6 +64,31 @@ struct ReturnPlan { guarded: Vec, } +/// Whether `cypher` (a statement without its prelude) has an updating clause +/// (CREATE / SET / REMOVE / DELETE) in any of its UNION arms. Reads only the +/// clause-list parser; a statement it does not read is not a write. Used by +/// the embedded dispatcher so a write in a later UNION arm (or one carrying a +/// COUNT { } the legacy parser cannot read) reaches the write path. +pub fn is_write_statement(cypher: &str) -> bool { + let Ok((_, stmt)) = crate::open_cypher_parser::clause_list::parse_clause_statement(cypher) + else { + return false; + }; + let arms: Vec<&crate::open_cypher_parser::clause_list::ClauseQuery<'_>> = + std::iter::once(&stmt.first) + .chain(stmt.unions.iter().map(|(_, q)| q)) + .collect(); + arms.iter().flat_map(|q| &q.clauses).any(|c| { + matches!( + c, + crate::open_cypher_parser::clause_list::Clause::Create(_) + | crate::open_cypher_parser::clause_list::Clause::Set(_) + | crate::open_cypher_parser::clause_list::Clause::Remove(_) + | crate::open_cypher_parser::clause_list::Clause::Delete(_) + ) + }) +} + /// Plan the write statement `cypher` (comments stripped). pub fn plan_write(cypher: &str, schema: &GraphSchema) -> Result { let (rest, stmt) = crate::open_cypher_parser::clause_list::parse_clause_statement(cypher)