Skip to content

Commit

Permalink
Serialize template rate laws to be None if the rate law doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
nanglo123 committed Sep 12, 2024
1 parent 854d614 commit 80ebe82
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion mira/metamodel/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ def from_json(cls, data, rate_symbols=None) -> "Template":

@field_serializer('rate_law')
def serialize_expression(self, rate_law):
return str(rate_law)
return str(rate_law) if rate_law is not None else None

def is_equal_to(self, other: "Template", with_context: bool = False,
config: Config = None) -> bool:
Expand Down
9 changes: 5 additions & 4 deletions tests/test_model_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,18 +589,19 @@ def test_n_way_comparison_askenet(self):
"exclude_defaults": True,
"exclude_unset": True,
"exclude_none": True,
# This key is outdated in Pydantic2
# "skip_defaults": True,
}
# Compare the ModelComparisonResponse models
# If assertion fails the diff is printed
# Use model dump as Pydantic objects have an attribute
# "model_fields_set" that contain explicitly set attributes even if
# are None
assert local_response.model_dump() == resp_model.model_dump()
local_sorted_str = sorted_json_str(
json.loads(local_response.model_dump_json()),
json.loads(local_response.model_dump_json(**dict_options)),
skip_empty=True
)
resp_sorted_str = sorted_json_str(
json.loads(resp_model.model_dump_json()),
json.loads(resp_model.model_dump_json(**dict_options)),
skip_empty=True
)
self.assertEqual(local_sorted_str, resp_sorted_str)
Expand Down

0 comments on commit 80ebe82

Please sign in to comment.