Skip to content

Commit 172b44a

Browse files
committed
skip converting empty yaml objects
1 parent 45f7743 commit 172b44a

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

iib/workers/tasks/fbc_utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,5 +169,8 @@ def enforce_json_config_dir(config_dir: str) -> None:
169169
with open(in_file, 'r') as yaml_in, open(out_file, 'a') as json_out:
170170
data = yaml.load_all(yaml_in)
171171
for chunk in data:
172+
# Ignore if it is an empty yaml object
173+
if chunk is None:
174+
continue
172175
json.dump(chunk, json_out, default=_serialize_datetime)
173176
os.remove(in_file)

tests/test_workers/test_tasks/test_fbc_utils.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,3 +300,25 @@ def test__serialize_datetime():
300300
def test__serialize_datetime_raise():
301301
with pytest.raises(TypeError, match="Type <class 'int'> is not serializable."):
302302
_serialize_datetime(2025)
303+
304+
305+
def test_enforce_json_config_dir_skips_empty_yaml_documents(tmpdir):
306+
yaml_with_empty_doc = """\
307+
---
308+
foo: bar
309+
---
310+
---
311+
another: data
312+
"""
313+
314+
expected_result = '{"foo": "bar"}{"another": "data"}'
315+
316+
input = os.path.join(tmpdir, "test_file.yaml")
317+
output = os.path.join(tmpdir, "test_file.json")
318+
with open(input, 'w') as w:
319+
w.write(dedent(yaml_with_empty_doc))
320+
321+
enforce_json_config_dir(tmpdir)
322+
323+
with open(output, 'r') as f:
324+
assert f.read() == expected_result

0 commit comments

Comments
 (0)