From 07165a907a01408485526950739183a6154f6515 Mon Sep 17 00:00:00 2001 From: Zane Bitter Date: Wed, 29 May 2019 15:57:42 -0400 Subject: [PATCH] Don't render None as "null" In a config file you never want the string "null" in place of a null value. Just render an empty string instead. Change-Id: Ibe145c4929d4944cd8d51c07a64aee6fd5f831f2 Closes-Bug: #1830967 Story: 2005797 (cherry picked from commit 75d527ab8fd13185f8db05ad69c43b3c89e06dc3) --- os_apply_config/renderers.py | 2 ++ os_apply_config/tests/test_apply_config.py | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/os_apply_config/renderers.py b/os_apply_config/renderers.py index 07b6cf2..bea6d05 100644 --- a/os_apply_config/renderers.py +++ b/os_apply_config/renderers.py @@ -38,4 +38,6 @@ class JsonRenderer(pystache.Renderer): partials, missing_tags) def str_coerce(self, val): + if val is None: + return b'' return json.dumps(val) diff --git a/os_apply_config/tests/test_apply_config.py b/os_apply_config/tests/test_apply_config.py index 76db3d9..8e921d4 100644 --- a/os_apply_config/tests/test_apply_config.py +++ b/os_apply_config/tests/test_apply_config.py @@ -337,6 +337,11 @@ class OSConfigApplierTestCase(testtools.TestCase): def test_render_moustache_bad_key(self): self.assertEqual(u'', apply_config.render_moustache("{{badkey}}", {})) + def test_render_moustache_none(self): + self.assertEqual('foo: ', + apply_config.render_moustache("foo: {{foo}}", + {'foo': None})) + def test_render_executable(self): params = {"x": "foo"} self.assertEqual("foo\n", apply_config.render_executable(