Skip to content

Commit 43a5b16

Browse files
committed
fix(io.yaml): drop metaData/version/_yaml_sections from doc['notes']
cobra's model_to_dict serialises model.notes verbatim into the output doc as the 'notes' section. write_yaml_model already pops these three management keys from a local copy of model.notes to use them as top-level YAML fields, but the originals remained on model.notes and therefore also leaked into doc['notes'], producing duplicate sections in the file (the legitimate top-level emit AND a nested copy inside notes). Strip them from doc['notes'] post-model_to_dict and drop the notes section entirely when nothing else is left. Discovered while round-tripping a geckopy ecModel (it stashes ec-rxns / ec-enzymes / gecko_light on model.notes['_yaml_sections']); was visible as duplicated GECKO sections in the written YAML.
1 parent b20a89e commit 43a5b16

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

src/raven_python/io/yaml.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,17 @@ def write_yaml_model(
179179

180180
doc = OrderedDict(_to_plain(model_to_dict(model)))
181181

182+
# cobra's model_to_dict serialises model.notes verbatim into doc["notes"],
183+
# so the three management keys we just lifted out would otherwise also
184+
# appear nested inside the notes section. Strip them; preserve any other
185+
# genuine notes the caller stored on the model.
186+
doc_notes = doc.get("notes")
187+
if isinstance(doc_notes, dict):
188+
for key in ("metaData", "version", "_yaml_sections"):
189+
doc_notes.pop(key, None)
190+
if not doc_notes:
191+
doc.pop("notes", None)
192+
182193
if sort_ids:
183194
for section in ("metabolites", "reactions", "genes"):
184195
if section in doc:

0 commit comments

Comments
 (0)