Skip to content

Commit

Permalink
config: handle empty or missing MicroflowConstants
Browse files Browse the repository at this point in the history
If the mxruntime/MicroflowConstants option is completely missing in the
config, this code would explode on the dictionary index.

If the option is present, but has no value specified as all, it ends up
as None, and causes an "AttributeError: 'NoneType' object has no
attribute 'items'" a few lines later, when asking for .items()

So, handle both scenarios in a better way.

Github: Fixes #39
  • Loading branch information
knorrie committed Aug 25, 2018
1 parent d14ef79 commit 47e6023
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/m2ee/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,9 @@ def get_constants(self):
model_constants = {}
for metadata_constant in self._model_metadata['Constants']:
model_constants[metadata_constant['Name']] = metadata_constant['DefaultValue']
yaml_constants = self._conf['mxruntime']['MicroflowConstants']
yaml_constants = self._conf['mxruntime'].get('MicroflowConstants', None)
if yaml_constants is None:
yaml_constants = {}
constants_to_use = {}
default_constants = {}
for name, value in model_constants.items():
Expand Down

0 comments on commit 47e6023

Please sign in to comment.