Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions core/engine/tests/decision.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,16 @@ fn decision_validation() {
DecisionGraphValidationError::InvalidInputCount(_)
));
}

#[tokio::test]
#[cfg_attr(miri, ignore)]
async fn nulls_are_preserved_when_merging_incoming_nodes() {
let table_content = load_test_data("test-null.json");
let decision = Decision::from(table_content);

let context = json!({ "b": null, "c": { "d": null } });
let result = decision.evaluate(context.into()).await;

assert_eq!(result.unwrap().result, json!({ "b": null, "c": { "d": null } }).into());
}

23 changes: 6 additions & 17 deletions core/expression/src/variable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,8 @@ fn merge_variables(
MergeStrategy::InPlace => {
let mut map = doc_ref.borrow_mut();
for (key, value) in patch.deref() {
if value == &Variable::Null {
map.remove(key.as_str());
} else {
let entry = map.entry(key.to_string()).or_insert(Variable::Null);
merge_variables(entry, value, false, strategy);
}
let entry = map.entry(key.to_string()).or_insert(Variable::Null);
merge_variables(entry, value, false, strategy);
}

return true;
Expand All @@ -292,17 +288,10 @@ fn merge_variables(
new_map.as_mut().unwrap()
};

if value == &Variable::Null {
// Remove null values
if map.remove(key.as_str()).is_some() {
changed = true;
}
} else {
// Handle nested merging
let entry = map.entry(key.to_string()).or_insert(Variable::Null);
if merge_variables(entry, value, false, strategy) {
changed = true;
}
// Handle nested merging
let entry = map.entry(key.to_string()).or_insert(Variable::Null);
if merge_variables(entry, value, false, strategy) {
changed = true;
}
}

Expand Down
37 changes: 37 additions & 0 deletions test-data/test-null.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"contentType": "application/vnd.gorules.decision",
"nodes": [
{
"id": "8f1971cc-1658-44b4-a64c-b6c734697e3d",
"name": "request",
"type": "inputNode",
"content": {
"schema": ""
},
"position": {
"x": 110,
"y": 114
}
},
{
"id": "aff016a9-1d4f-4d5d-98a5-adf4f367f371",
"name": "response",
"type": "outputNode",
"content": {
"schema": ""
},
"position": {
"x": 750,
"y": 114
}
}
],
"edges": [
{
"id": "8dd114f0-06b3-4f7e-9213-4faaa5a855c8",
"type": "edge",
"sourceId": "8f1971cc-1658-44b4-a64c-b6c734697e3d",
"targetId": "aff016a9-1d4f-4d5d-98a5-adf4f367f371"
}
]
}