Closed yulqen closed 5 years ago
Removing raise
from last line allows the parsing to pass and returns a None
value at present. Need to sort out the logic behind the KeyErrors
at the end of _comb_with_datamap()
:
def _comb_with_datamap(self, filename, template_data, datamap_data, key, sheet):
"""Given a filename, a template_data json str, a datamap_data dict, key and sheet, returns
the value in the spreadsheet at given datamap key.
Throws KeyError if the datamap refers to a sheet/cellref combo in the target file that does not exist.
"""
_data_lst = json.loads(datamap_data)
if key not in [x["key"] for x in _data_lst]:
raise KeyError('No key "{}" in datamap'.format(key))
if sheet not in [x["sheet"] for x in _data_lst]:
raise KeyError('No sheet "{}" in datamap'.format(sheet))
_target_cellref = [
x["cellref"] for x in _data_lst if x["key"] == key and x["sheet"] == sheet
]
_cellref = _target_cellref[0]
try:
output = json.loads(template_data)[filename]["data"][sheet][_cellref][
"value"
]
return output
except KeyError:
logger.critical(
"Unable to handle value {} or {} when processing {} with datamap.".format(
sheet, _cellref, filename
)
)
raise KeyError(
"Unable to handle value {} or {} when processing {} with datamap.".format(
sheet, _cellref, filename
)
)
Empty cells return None
for now, and fixed exception to properly flag a file being processed which contains a sheet that is not referenced in the datamap.
The
KeyError
raised here inengine.use_cases.parsing
:is a result of an empty cell. Empty cells should need to be handled according to the user requirement - either a None or empty string.