Fix KeyError when deleting nonexistent keys

`hidden_meta` saves not only the existing hidden meta keys, but also
those who don't exist with value `None`. For example:
```
{'capa/path': None, 'capa/nursery': None}
```

Deleting nonexistent keys raises a `KeyError` exception.
This commit is contained in:
Ana María Martínez Gómez
2020-06-30 14:21:39 +02:00
parent 5cbfbc4997
commit 8e78d8de53

View File

@@ -590,10 +590,11 @@ class Rule(object):
# save off the existing hidden meta values, # save off the existing hidden meta values,
# emit the document, # emit the document,
# and re-add the hidden meta. # and re-add the hidden meta.
hidden_meta = { hidden_meta = {}
key: meta.get(key) for key in HIDDEN_META_KEYS:
for key in HIDDEN_META_KEYS value = meta.get(key)
} if value:
hidden_meta[key] = value
for key in hidden_meta.keys(): for key in hidden_meta.keys():
del meta[key] del meta[key]