8000 Fixed issue #18053: Computed Values become null when Schema is modifi… · olegrok/arangodb@658a461 · GitHub
[go: up one dir, main page]

Skip to content

Commit 658a461

Browse files
authored
Fixed issue arangodb#18053: Computed Values become null when Schema is modified (arangodb#18056)
1 parent 11002f6 commit 658a461

File tree

3 files changed

+75
-13
lines changed

3 files changed

+75
-13
lines changed

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
devel
22
-----
33

4+
* Fixed issue #18053: Computed Values become null when Schema is modified.
5+
46
* BTS-1193: Fix for schema update. When removing a field and then inserting a
57
new field into the schema, previously, both old and new schema would be
68
merged, meaning it would maintain the old field and add the new one.

arangod/VocBase/LogicalCollection.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -272,16 +272,17 @@ Result LogicalCollection::updateSchema(VPackSlice schema) {
272272
}
273273

274274
Result LogicalCollection::updateComputedValues(VPackSlice computedValues) {
275-
auto result =
276-
ComputedValues::buildInstance(vocbase(), shardKeys(), computedValues);
275+
if (!computedValues.isNone()) {
276+
auto result =
277+
ComputedValues::buildInstance(vocbase(), shardKeys(), computedValues);
277278

278-
if (result.fail()) {
279-
return result.result();
280-
}
281-
282-
std::atomic_store_explicit(&_computedValues, result.get(),
283-
std::memory_order_release);
279+
if (result.fail()) {
280+
return result.result();
281+
}
284282

283+
std::atomic_store_explicit(&_computedValues, result.get(),
284+
std::memory_order_release);
285+
}
285286
return {};
286287
}
287288

tests/js/common/shell/shell-collection-computed-values.js

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ function ComputedValuesAfterCreateCollectionTestSuite() {
723723
}
724724
},
725725

726-
testNowAllowedLet: function() {
726+
testNotAllowedLet: function() {
727727
try {
728728
collection.properties({
729729
computedValues: [
@@ -739,8 +739,67 @@ function ComputedValuesAfterCreateCollectionTestSuite() {
739739
assertEqual(errors.ERROR_BAD_PARAMETER.code, error.errorNum);
740740
}
741741
},
742+
743+
testInteractionBetweenSchemaAndComputedValues: function() {
744+
const schema = {
745+
rule: {
746+
type: "object",
747+
properties: {
748+
value1: {
749+
type: "boolean",
750+
},
751+
},
752+
required: ["value1"],
753+
},
754+
level: "moderate",
755+
message: "Schema validation failed",
756+
type: "json",
757+
};
758+
759+
const computedValues = [
760+
{
761+
name: "value1",
762+
expression: "RETURN CONCAT(@doc.value1, '+', @doc.value2)",
763+
computeOn: ["insert", "update", "replace"],
764+
overwrite: true,
765+
failOnWarning: false,
766+
keepNull: true,
767+
}
768+
];
769+
770+
collection.properties({ schema, computedValues });
771+
772+
if (isCluster) {
773+
// unfortunately there is no way to test when the new properties
774+
// have been applied on the DB servers. all we can do is sleep
775+
// and hope the delay is long enough
776+
internal.sleep(5);
777+
}
778+
779+
let colProperties = collection.properties();
780+
assertTrue(colProperties.hasOwnProperty("schema"));
781+
assertEqual(schema, colProperties.schema);
782+
assertTrue(colProperties.hasOwnProperty("computedValues"));
783+
assertEqual(computedValues, colProperties.computedValues);
784+
785+
// update just the schema
786+
collection.properties({ schema });
787+
788+
if (isCluster) {
789+
// unfortunately there is no way to test when the new properties
790+
// have been applied on the DB servers. all we can do is sleep
791+
// and hope the delay is long enough
792+
internal.sleep(5);
793+
}
794+
795+
colProperties = collection.properties();
796+
assertTrue(colProperties.hasOwnProperty("schema"));
797+
assertEqual(schema, colProperties.schema);
798+
assertTrue(colProperties.hasOwnProperty("computedValues"));
799+
assertEqual(computedValues, colProperties.computedValues);
800+
},
742801

743-
testSchemaValidationWithComputedValuesoverwrite: function() {
802+
testSchemaValidationWithComputedValuesOverwrite: function() {
744803
collection.properties({
745804
schema: {
746805
"rule": {
@@ -791,7 +850,7 @@ function ComputedValuesAfterCreateCollectionTestSuite() {
791850
assertEqual(res.length, 0);
792851
},
793852

794-
testSchemaValidationWithComputedValuesNooverwrite: function() {
853+
testSchemaValidationWithComputedValuesNoOverwrite: function() {
795854
collection.properties({
796855
schema: {
797856
"rule": {
@@ -846,7 +905,7 @@ function ComputedValuesAfterCreateCollectionTestSuite() {
846905
},
847906

848907

849-
testRedefineComputedValueUpdateoverwrite: function() {
908+
testRedefineComputedValueUpdateOverwrite: function() {
850909
collection.properties({
851910
computedValues: [
852911
{
@@ -921,7 +980,7 @@ function ComputedValuesAfterCreateCollectionTestSuite() {
921980
});
922981
},
923982

924-
testRedefineComputedValueUpdateNooverwrite: function() {
983+
testRedefineComputedValueUpdateNoOverwrite: function() {
925984
collection.properties({
926985
computedValues: [
927986
{

0 commit comments

Comments
 (0)
0