From e190393397ca2c59abcbda7a7b9b73c949b27e85 Mon Sep 17 00:00:00 2001 From: Konstantin Demin Date: Fri, 8 Nov 2024 14:19:37 +0300 Subject: [PATCH] j2cfg: allow empty list/map overrides --- j2cfg/j2cfg/functions.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/j2cfg/j2cfg/functions.py b/j2cfg/j2cfg/functions.py index 480d791..6ba995d 100644 --- a/j2cfg/j2cfg/functions.py +++ b/j2cfg/j2cfg/functions.py @@ -278,11 +278,19 @@ def merge_dict_recurse(d1, d2: dict) -> dict: map_common = {k for k in map1 if is_mapping(d2.get(k))} for k in map_common: - x[k] = merge_dict_recurse(x.get(k), d2.get(k)) + y = d2.get(k) + if not y: + x[k] = {} + continue + x[k] = merge_dict_recurse(x.get(k), y) seq_common = {k for k in seq1 if is_sequence(d2.get(k))} for k in seq_common: - x[k] = uniq(list(x.get(k)) + list(d2.get(k))) + y = d2.get(k) + if not y: + x[k] = [] + continue + x[k] = uniq(list(x.get(k)) + list(y)) unmerged = (map1 - map_common) | (seq1 - seq_common) for k in unmerged: