From 7588c7e31a63beaf92de952bec662d6e884f23ab Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Mon, 2 Sep 2024 10:13:47 +0100 Subject: [PATCH] Fix bug with object array-indexed string field names appearing with quotation marks (#4657) --- core/src/sql/value/set.rs | 2 +- sdk/tests/update.rs | 40 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/core/src/sql/value/set.rs b/core/src/sql/value/set.rs index b4bdd9f2..3d633d74 100644 --- a/core/src/sql/value/set.rs +++ b/core/src/sql/value/set.rs @@ -65,7 +65,7 @@ impl Value { _ => { let mut obj = Value::base(); stk.run(|stk| obj.set(stk, ctx, opt, path.next(), val)).await?; - v.insert(f.to_string(), obj); + v.insert(f.to_raw(), obj); Ok(()) } }, diff --git a/sdk/tests/update.rs b/sdk/tests/update.rs index 3ce62430..e396e218 100644 --- a/sdk/tests/update.rs +++ b/sdk/tests/update.rs @@ -282,6 +282,46 @@ async fn update_with_return_clause() -> Result<(), Error> { Ok(()) } +#[tokio::test] +async fn update_with_object_array_string_field_names() -> Result<(), Error> { + let sql = " + UPSERT person:one SET field.key = 'value'; + UPSERT person:two SET field['key'] = 'value'; + "; + let dbs = new_ds().await?; + let ses = Session::owner().with_ns("test").with_db("test"); + let res = &mut dbs.execute(sql, &ses, None).await?; + assert_eq!(res.len(), 2); + // + let tmp = res.remove(0).result?; + let val = Value::parse( + "[ + { + field: { + key: 'value' + }, + id: person:one + } + ]", + ); + assert_eq!(tmp, val); + // + let tmp = res.remove(0).result?; + let val = Value::parse( + "[ + { + field: { + key: 'value' + }, + id: person:two + } + ]", + ); + assert_eq!(tmp, val); + // + Ok(()) +} + // // Permissions //