Skip to content

Commit

Permalink
fixes dict merge, leave dst values flag
Browse files Browse the repository at this point in the history
  • Loading branch information
rudolfix committed Feb 29, 2024
1 parent 35e1319 commit fe1a65f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
3 changes: 2 additions & 1 deletion dlt/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions tests/common/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
extend_list_deduplicated,
get_exception_trace,
get_exception_trace_chain,
update_dict_nested,
)


Expand Down Expand Up @@ -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
)
4 changes: 3 additions & 1 deletion tests/load/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down

0 comments on commit fe1a65f

Please sign in to comment.