From 1ce6c4bae62809a141e6d367c984e62ca554e6f6 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Thu, 22 Dec 2022 08:33:57 +0000 Subject: [PATCH] Process futures before using as function arguments Closes #1538 --- lib/src/sql/function.rs | 2 ++ lib/tests/future.rs | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/lib/src/sql/function.rs b/lib/src/sql/function.rs index 168197af..29d99bae 100644 --- a/lib/src/sql/function.rs +++ b/lib/src/sql/function.rs @@ -113,6 +113,8 @@ impl Function { ) -> Result { // Prevent long function chains let opt = &opt.dive(1)?; + // Ensure futures are run + let opt = &opt.futures(true); // Process the function type match self { Self::Cast(s, x) => { diff --git a/lib/tests/future.rs b/lib/tests/future.rs index c1a0d9bc..fdb2cc27 100644 --- a/lib/tests/future.rs +++ b/lib/tests/future.rs @@ -33,3 +33,35 @@ async fn future_function_simple() -> Result<(), Error> { // Ok(()) } + +#[tokio::test] +async fn future_function_arguments() -> Result<(), Error> { + let sql = " + UPDATE future:test SET + a = 'test@surrealdb.com', + b = { 'test@surrealdb.com' }, + x = 'a-' + parse::email::user(a), + y = 'b-' + parse::email::user(b) + ; + "; + let dbs = Datastore::new("memory").await?; + let ses = Session::for_kv().with_ns("test").with_db("test"); + let res = &mut dbs.execute(&sql, &ses, None, false).await?; + assert_eq!(res.len(), 1); + // + let tmp = res.remove(0).result?; + let val = Value::parse( + "[ + { + a: 'test@surrealdb.com', + b: 'test@surrealdb.com', + id: 'future:test', + x: 'a-test', + y: 'b-test', + } + ]", + ); + assert_eq!(tmp, val); + // + Ok(()) +}