From 7988c8aded83bd05f2f54b325d3049a8c0dbffed Mon Sep 17 00:00:00 2001 From: Zoran Cvetkov Date: Sat, 1 Feb 2025 23:12:07 +0200 Subject: [PATCH 1/3] fix wrong merge --- graph/src/components/store/entity_cache.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/graph/src/components/store/entity_cache.rs b/graph/src/components/store/entity_cache.rs index a9cb90f3004..fe39a0bbe30 100644 --- a/graph/src/components/store/entity_cache.rs +++ b/graph/src/components/store/entity_cache.rs @@ -288,7 +288,7 @@ impl EntityCache { ) -> Result, anyhow::Error> { match op { EntityOp::Update(entity) | EntityOp::Overwrite(entity) - if query.matches(key, &entity) => + if query.matches(key, entity) => { Ok(Some(entity.clone())) } @@ -383,6 +383,7 @@ impl EntityCache { // The next VID is based on a block number and a sequence within the block let vid = ((block as i64) << 32) + self.vid_seq as i64; + self.vid_seq += 1; let mut entity = entity; let old_vid = entity.set_vid(vid).expect("the vid should be set"); // Make sure that there was no VID previously set for this entity. @@ -395,6 +396,8 @@ impl EntityCache { ); } + self.entity_op(key.clone(), EntityOp::Update(entity)); + // The updates we were given are not valid by themselves; force a // lookup in the database and check again with an entity that merges // the existing entity with the changes From 1ae5dd78c0404db14539afd0a392f8a96b385e3e Mon Sep 17 00:00:00 2001 From: Zoran Cvetkov Date: Sun, 2 Feb 2025 11:26:47 +0200 Subject: [PATCH 2/3] fix a test --- graph/src/data/store/mod.rs | 4 ++-- store/test-store/tests/postgres/relational.rs | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/graph/src/data/store/mod.rs b/graph/src/data/store/mod.rs index 5f690d49ece..2a4da6ae526 100644 --- a/graph/src/data/store/mod.rs +++ b/graph/src/data/store/mod.rs @@ -914,9 +914,9 @@ impl Entity { /// i64 it panics. pub fn vid(&self) -> i64 { self.get(VID_FIELD) - .expect("the vid is set") + .expect("the vid must be set") .as_int8() - .expect("the vid is set to a valid value") + .expect("the vid must be set to a valid value") } /// Sets the VID of the entity. The previous one is returned. diff --git a/store/test-store/tests/postgres/relational.rs b/store/test-store/tests/postgres/relational.rs index 9f11c50b07a..5d01bd3c510 100644 --- a/store/test-store/tests/postgres/relational.rs +++ b/store/test-store/tests/postgres/relational.rs @@ -778,7 +778,8 @@ fn enum_arrays() { let spectrum = entity! { THINGS_SCHEMA => id: "rainbow", main: "yellow", - all: vec!["yellow", "red", "BLUE"] + all: vec!["yellow", "red", "BLUE"], + vid: 0i64 }; insert_entity( From 46fa0f4b625efa4862dc9d37708aa37edab9daa0 Mon Sep 17 00:00:00 2001 From: Zoran Cvetkov Date: Sun, 2 Feb 2025 11:27:53 +0200 Subject: [PATCH 3/3] add vid to the list of selected columns --- store/postgres/src/relational/dsl.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/store/postgres/src/relational/dsl.rs b/store/postgres/src/relational/dsl.rs index 6812bbb37e9..4307fc7c776 100644 --- a/store/postgres/src/relational/dsl.rs +++ b/store/postgres/src/relational/dsl.rs @@ -254,7 +254,10 @@ impl<'a> Table<'a> { } match column_names { - AttributeNames::All => cols.extend(self.meta.columns.iter()), + AttributeNames::All => { + cols.extend(self.meta.columns.iter()); + cols.push(&*VID_COL); + } AttributeNames::Select(names) => { let pk = self.meta.primary_key(); cols.push(pk);