Fix saving YAML as JSON with empty array (#19057)

* Fix saving YAML as JSON with empty array

* Lint
This commit is contained in:
Bram Kragten 2018-12-06 09:24:49 +01:00 committed by Paulus Schoutsen
parent b71d65015a
commit b9ed4b7a76

View File

@ -267,6 +267,8 @@ def add_card(fname: str, view_id: str, card_config: str,
if str(view.get('id', '')) != view_id:
continue
cards = view.get('cards', [])
if not cards and 'cards' in view:
del view['cards']
if data_format == FORMAT_YAML:
card_config = yaml.yaml_to_object(card_config)
if 'id' not in card_config:
@ -275,6 +277,8 @@ def add_card(fname: str, view_id: str, card_config: str,
cards.append(card_config)
else:
cards.insert(position, card_config)
if 'cards' not in view:
view['cards'] = cards
yaml.save_yaml(fname, config)
return
@ -402,6 +406,8 @@ def add_view(fname: str, view_config: str,
views.append(view_config)
else:
views.insert(position, view_config)
if 'views' not in config:
config['views'] = views
yaml.save_yaml(fname, config)