Skip to content

Commit

Permalink
report smaller diffs by dropping null values.
Browse files Browse the repository at this point in the history
This should result in not showing fields that were unset to begin with,
and mark fields that were explicitly removed as "deleted" instead of
"replaced by ``null``"
  • Loading branch information
evgeni committed May 2, 2022
1 parent 7b554b2 commit 215933a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/smaller-diffs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- all modules - report smaller diffs by dropping ``null`` values. This should result in not showing fields that were unset to begin with, and mark fields that were explicitly removed as "deleted" instead of "replaced by ``null``"
12 changes: 10 additions & 2 deletions plugins/module_utils/foreman_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -946,10 +946,18 @@ def auto_lookup_nested_entities(self):
item[nested_key] = self._lookup_entity(item[nested_key], nested_spec)

def record_before(self, resource, entity):
self._before[resource].append(entity)
if isinstance(entity, dict):
to_record = _recursive_dict_without_none(entity)
else:
to_record = entity
self._before[resource].append(to_record)

def record_after(self, resource, entity):
self._after[resource].append(entity)
if isinstance(entity, dict):
to_record = _recursive_dict_without_none(entity)
else:
to_record = entity
self._after[resource].append(to_record)

def record_after_full(self, resource, entity):
self._after_full[resource].append(entity)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_playbooks/activation_key.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
expected_change: true
expected_diff: true
expected_diff_before: "Test_Organization_Test_Product_Test_Repository.*false"
expected_diff_after: "Test_Organization_Test_Product_Test_Repository.*null"
expected_diff_after: "content_overrides.*{}"
- name: update AK with content overrides set to default again, no change
include_tasks: tasks/activation_key.yml
vars:
Expand Down

0 comments on commit 215933a

Please sign in to comment.