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
2 changes: 2 additions & 0 deletions hierarchical_conf/hierarchical_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ def _deep_update(
if isinstance(value, Mapping) and value:
returned = self._deep_update(source.get(key, {}), value)
source[key] = returned
elif value is None:
source.pop(key, None)
Comment on lines +120 to +121
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would we want to choose wether the key is removed or it's persisted with the None value? There may be some situations where we would like to keep the key with the None, or am I being to picky?

else:
source[key] = overrides[key]
return source
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import setup, find_packages

__package_name__ = "hierarchical_conf"
__version__ = "1.0.3"
__version__ = "1.0.4"
__repository_url__ = "https://github.com/quintoandar/hierarchical-conf"


Expand Down
15 changes: 15 additions & 0 deletions tests/unit/test_hierarchical_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,18 @@ def test_deep_update(self, hierarchical_conf):

# assert
assert returned_value == expected_value

def test_deep_update_deleting_nulls(self, hierarchical_conf):
# arrange
expected_value = {"key2": "new value", "key3": {"a": 1}}
source = {
"key1": "val1",
"key2": "val2",
}
overrides = {"key1": None, "key2": "new value", "key3": {"a": 1}}

# act
returned_value = hierarchical_conf._deep_update(source, overrides)

# assert
assert returned_value == expected_value