From 24d2fe5475f0be5090534c8df15e1ae116e80455 Mon Sep 17 00:00:00 2001 From: pkoprda <47797196+pkoprda@users.noreply.github.com> Date: Wed, 15 Jan 2025 13:47:50 +0100 Subject: [PATCH] fix(client): Serialize properly playbooks with empty maps (#4340) * 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 (cherry picked from commit be6a4ba8ae353fde7024e96d8942e905a347bdd1) --- .../client/apps/ansible/playbook_verifier/serializer.py | 2 ++ insights/tests/client/apps/test_playbook_verifier.py | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/insights/client/apps/ansible/playbook_verifier/serializer.py b/insights/client/apps/ansible/playbook_verifier/serializer.py index 33defd850..12daafe5a 100644 --- a/insights/client/apps/ansible/playbook_verifier/serializer.py +++ b/insights/client/apps/ansible/playbook_verifier/serializer.py @@ -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)) diff --git a/insights/tests/client/apps/test_playbook_verifier.py b/insights/tests/client/apps/test_playbook_verifier.py index 4a95aaa97..1ea422fbb 100644 --- a/insights/tests/client/apps/test_playbook_verifier.py +++ b/insights/tests/client/apps/test_playbook_verifier.py @@ -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)