Skip to content

Commit

Permalink
fix(client): Serialize properly playbooks with empty maps (#4340)
Browse files Browse the repository at this point in the history
* Card ID: CCT-1101

Empty maps in playbooks were not being correctly handled by the
serializer. To maintain compatibility across various environments,
they are now serialized as `ordereddict()`.

Signed-off-by: pkoprda <[email protected]>
(cherry picked from commit be6a4ba)
  • Loading branch information
pkoprda authored and xiangce committed Jan 16, 2025
1 parent 9de71ef commit 24d2fe5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions insights/client/apps/ansible/playbook_verifier/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ def _dict(cls, value):
:type value: dict | yaml.comments.CommentedMap
:rtype: str
"""
if not value:
return "ordereddict()"
result = "ordereddict(["
result += ", ".join(
"('{key}', {value})".format(key=k, value=cls._obj(v))
Expand Down
6 changes: 6 additions & 0 deletions insights/tests/client/apps/test_playbook_verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,12 @@ def test_list(self):
expected = "['value1', 'value2']"
assert result == expected

def test_dict_empty(self):
source = {}
result = playbook_verifier.PlaybookSerializer.serialize(source)
expected = "ordereddict()"
assert result == expected

def test_dict_empty_value(self):
source = {"key": None}
result = playbook_verifier.PlaybookSerializer.serialize(source)
Expand Down

0 comments on commit 24d2fe5

Please sign in to comment.