diff --git a/CHANGELOG b/CHANGELOG index 9ecd3d9a86cc..31a7d30fd20b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,8 @@ v3.7.10 (XXXX-XX-XX) -------------------- +* Fixed Github issue #13632: Query Fails on Upsert with Replace_nth. + * Fixed a problem that coordinators would vanish from the UI and the Health API if one switched the agency Supervision into maintenance mode and kept left that maintenance mode on for more than 24h. diff --git a/arangod/Aql/Functions.cpp b/arangod/Aql/Functions.cpp index 9ed344028c57..c5db143d798b 100644 --- a/arangod/Aql/Functions.cpp +++ b/arangod/Aql/Functions.cpp @@ -7340,9 +7340,10 @@ AqlValue Functions::ReplaceNth(ExpressionContext* expressionContext, THROW_ARANGO_EXCEPTION_PARAMS(TRI_ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, AFN); } - AqlValueMaterializer materializer(trx); - VPackSlice arraySlice = materializer.slice(baseArray, false); - VPackSlice replaceValue = materializer.slice(newValue, false); + AqlValueMaterializer materializer1(trx); + VPackSlice arraySlice = materializer1.slice(baseArray, false); + AqlValueMaterializer materializer2(trx); + VPackSlice replaceValue = materializer2.slice(newValue, false); transaction::BuilderLeaser builder(trx); builder->openArray(); @@ -7359,6 +7360,7 @@ AqlValue Functions::ReplaceNth(ExpressionContext* expressionContext, uint64_t pos = length; if (replaceOffset >= length) { + AqlValueMaterializer materializer(trx); VPackSlice paddVpValue = materializer.slice(paddValue, false); while (pos < replaceOffset) { builder->add(paddVpValue); diff --git a/tests/js/server/aql/aql-functions.js b/tests/js/server/aql/aql-functions.js index 980ee637856d..0ce579dd324e 100644 --- a/tests/js/server/aql/aql-functions.js +++ b/tests/js/server/aql/aql-functions.js @@ -885,7 +885,6 @@ function ahuacatlFunctionsTestSuite () { //////////////////////////////////////////////////////////////////////////////// testReplaceNthCxx : function () { - var testArray = [ null, true, @@ -939,6 +938,39 @@ function ahuacatlFunctionsTestSuite () { } }, + testReplaceNthIssue13632 : function () { + const cn = "UnitTestsCollection"; + db._drop(cn); + db._create(cn); + try { + let query = ` + LET values = [["t1", 0, 0], ["t1", 1, 0]] + FOR value_set IN values + LET t = value_set[0] + LET index = value_set[1] + LET value = value_set[2] + UPSERT {} + INSERT {v: {[t]: []}} + UPDATE { + 'v' : {[t]: REPLACE_NTH(OLD.v[t], index, value, value)} + } IN ${cn} + RETURN [OLD, NEW]`; + let actual = getQueryResults(query); + assertEqual(2, actual.length); + + let OLD, NEW; + [OLD, NEW] = actual[0]; + assertNull(OLD); + assertEqual({ t1: [] }, NEW.v); + + [OLD, NEW] = actual[1]; + assertEqual({ t1: [] }, OLD.v); + assertEqual({ t1: [0, 0] }, NEW.v); + } finally { + db._drop(cn); + } + }, + //////////////////////////////////////////////////////////////////////////////// /// @brief test replace_nth function ////////////////////////////////////////////////////////////////////////////////