From 17360f56c7657e49d2b5da2fafa5d8d633d556f7 Mon Sep 17 00:00:00 2001 From: David Lutterkort Date: Thu, 10 Apr 2025 09:42:21 -0700 Subject: [PATCH] graph: Allow remove followed by remove in write batches If subgraphs delete entities without checking if they exist, we get two removes in a row. In the database, the second remove would just lead to a query that changes nothing. We'll do the same when putting a write batch together. Fixes https://github.com/graphprotocol/graph-node/issues/5449 --- graph/src/components/store/write.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/graph/src/components/store/write.rs b/graph/src/components/store/write.rs index aa56fdcc910..6f899633bd8 100644 --- a/graph/src/components/store/write.rs +++ b/graph/src/components/store/write.rs @@ -439,7 +439,7 @@ impl RowGroup { // clamping an old version match (&*prev_row, &row) { (Insert { end: None, .. } | Overwrite { end: None, .. }, Insert { .. }) - | (Remove { .. }, Overwrite { .. } | Remove { .. }) + | (Remove { .. }, Overwrite { .. }) | ( Insert { end: Some(_), .. } | Overwrite { end: Some(_), .. }, Overwrite { .. } | Remove { .. }, @@ -450,6 +450,11 @@ impl RowGroup { row )) } + (Remove { .. }, Remove { .. }) => { + // Ignore the new row, since prev_row is already a + // delete. This can happen when subgraphs delete + // entities without checking if they even exist + } ( Insert { end: Some(_), .. } | Overwrite { end: Some(_), .. } | Remove { .. }, Insert { .. },