Closed afoglia closed 3 years ago
Thanks for taking the time to report the issue and to look for a solution!
Would you happen to have a short mx2 file to share?
We currently don't have one to test with...
This is as fixed as I could make it, for the time being.
Should anyone have a problematic file, please share it!
I was trying to import an mx2 file of all my recipes, and got a failure a dozen or so recipes in. I traced it to the fact my mx2 file has an empty IngR tag. Multiple recipes in my file have these empty IngR tags.
I suspect what happened is I added a blank row to the ingredient list in Mastercook, and that was what translated into the empty tag. (These recipes are over 15 years old.)
Steps to Reproduce
Expected Behavior
The importer should just skip over empty IngR tags.
Current Behavior
The problem arises in MastercookXMLHandler.IngR_handler.
IngR_handler gets called twice for an empty tag. Once with start=True, end=False, attrs=None (or something else falsy).
The first call does nothing. The second call starts the commit. But self.ing has been cleared when the previous ingredient was commited (Importer.finish_ing), so the self.ing['unit'] in the debug call on line 194 raises a KeyError.
Possible Solution
Just fixing the debug to use self.ing.get('unit') is not likely to work. commit_ing may not require 'unit', but the item information is still that of the previous IngR tag.
Instead, I suggest adding a check at the beginning of IngR_handler to reset the item-related attributes specific to MastercookXMLHandler.
Then replace the
if end:
check with 'if end and self.item
which will only commit an ingredient if one was read in.Environment