Skip to content

Commit 3ee2caa

Browse files
NicolappsConvex, Inc.
authored and
Convex, Inc.
committed
Fix ConvexObject::filter_system_fields (#25873)
The previous implementation of ConvexObject::filter_system_fields modified `fields` but not `size` (or `nesting`) while it can change, which causes equality comparisons to fail. This commit also adds a test which fails with the previous implementation but passes with the new one. GitOrigin-RevId: abcd1d985efc047225013ad3eca7f590ec275db8
1 parent 082360e commit 3ee2caa

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

crates/value/src/object.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,13 @@ impl ConvexObject {
167167
}
168168

169169
pub fn filter_system_fields(self) -> Self {
170-
Self {
171-
size: self.size,
172-
nesting: self.nesting,
173-
fields: self
174-
.fields
175-
.into_iter()
176-
.filter(|(k, _)| !k.is_system())
177-
.collect(),
178-
}
170+
let filtered_fields: BTreeMap<_, _> = self
171+
.fields
172+
.into_iter()
173+
.filter(|(k, _)| !k.is_system())
174+
.collect();
175+
Self::try_from(filtered_fields)
176+
.expect("Filtering an object should always produce a smaller, thus valid object")
179177
}
180178
}
181179

crates/value/src/tests.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,18 @@ fn test_object_keys() -> anyhow::Result<()> {
166166
.contains("Field name $id starts with '$', which is reserved"));
167167
Ok(())
168168
}
169+
170+
#[test]
171+
fn test_filter_system_fields() {
172+
assert_eq!(
173+
assert_obj!(
174+
"_id" => "j571sbvz5zj1ps44j9f433pf1n6s7egs",
175+
"_creationTime" => 1715895391903.0,
176+
"name" => "Nicolas",
177+
)
178+
.filter_system_fields(),
179+
assert_obj!(
180+
"name" => "Nicolas",
181+
)
182+
)
183+
}

0 commit comments

Comments
 (0)