diff --git a/dlt/common/utils.py b/dlt/common/utils.py index 656cf1cdc4..9beb4e48bf 100644 --- a/dlt/common/utils.py +++ b/dlt/common/utils.py @@ -292,7 +292,8 @@ def _is_recursive_merge(a: StrAny, b: StrAny) -> bool: # If a key exists in both objects and the values are `same`, the value from the `dst` object will be used. pass else: - if keep_dst_values: + if not keep_dst_values: + # if not keep then overwrite dst[key] = src[key] else: # If the key exists only in `src`, the value from the `src` object will be used. diff --git a/tests/common/test_utils.py b/tests/common/test_utils.py index 7cd8e9f1a2..2cf3fa9bf0 100644 --- a/tests/common/test_utils.py +++ b/tests/common/test_utils.py @@ -21,6 +21,7 @@ extend_list_deduplicated, get_exception_trace, get_exception_trace_chain, + update_dict_nested, ) @@ -277,3 +278,14 @@ def test_exception_trace_chain() -> None: assert traces[0]["exception_type"] == "dlt.common.exceptions.PipelineException" assert traces[1]["exception_type"] == "dlt.common.exceptions.IdentifierTooLongException" assert traces[2]["exception_type"] == "dlt.common.exceptions.TerminalValueError" + + +def test_nested_dict_merge() -> None: + dict_1 = {"a": 1, "b": 2} + dict_2 = {"a": 2, "c": 4} + + assert update_dict_nested(dict_1, dict_2) == {"a": 2, "b": 2, "c": 4} + assert update_dict_nested(dict_2, dict_1) == {"a": 1, "b": 2, "c": 4} + assert update_dict_nested(dict_1, dict_2, keep_dst_values=True) == update_dict_nested( + dict_2, dict_1 + ) diff --git a/tests/load/utils.py b/tests/load/utils.py index 3d331986bb..7b4cf72b47 100644 --- a/tests/load/utils.py +++ b/tests/load/utils.py @@ -386,7 +386,9 @@ def destinations_configs( if not isinstance(file_format, Sequence): file_format = [file_format] destination_configs = [ - conf for conf in destination_configs if conf.file_format in file_format + conf + for conf in destination_configs + if conf.file_format and conf.file_format in file_format ] if supports_merge is not None: destination_configs = [