Skip to content

modelspec/base_types.py:to_json_file triggers KeyError: 'id' #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
robertvi opened this issue Jul 29, 2023 · 1 comment
Open

modelspec/base_types.py:to_json_file triggers KeyError: 'id' #1

robertvi opened this issue Jul 29, 2023 · 1 comment

Comments

@robertvi
Copy link
Collaborator

robertvi commented Jul 29, 2023

see test_id_bug.py
andtest_sid_fix.py

In test_id_bug.py I create a fragment of the SBML specification in modelspec, whereby the id field has to be defined as optional as per the spec doc

whenever an object that gets stored in a list is not assigned an id this triggers a KeyError when trying to convert to json using modelspec/base_types.py:to_json_file (presumably because the id is trying to be used as the key for a dictionary where the other attributes of the object are going to be stored)

'''
sbml_doc = SBML(id=sbml_id) #no error if id is None

model = Model(id=model_id) #no error if id is None
sbml_doc.model = model

unitDef = UnitDefinition(id=unitdef_id) #ERROR if id is None
model.listOfUnitDefinitions.append(unitDef)

unit = Unit(id=unit_id)#Error if id is None
unitDef.listOfUnits.append(unit)

#this triggers the error
sbml_doc.to_json_file(f"untracked/test_id_bug.{fname}.json")

'''

@robertvi
Copy link
Collaborator Author

robertvi commented Jul 29, 2023

It is not yet clear if we need to use the special (for modelspec) attribute name 'id' and work around this bug, or if my current workaround of using the attribute 'sid' in place of 'id' (which prevents this bug from triggering) will be better. It will come down to how the serialisation to XML is implemented.

using sid as a workaround is implemented in test_sid_fix.py and is being used in the main spec file sbml32spec.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant