Dont raise a KeyError in get_item_id() when the field does not exist

This commit is contained in:
Kovid Goyal 2022-09-15 08:41:39 +05:30
parent 315575aa56
commit ca01ac7326
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -810,7 +810,10 @@ class Cache:
@read_api
def get_item_id(self, field, item_name):
' Return the item id for item_name (case-insensitive) '
try:
rmap = {icu_lower(v) if isinstance(v, str) else v:k for k, v in iteritems(self.fields[field].table.id_map)}
except KeyError:
rmap = {}
return rmap.get(icu_lower(item_name) if isinstance(item_name, str) else item_name, None)
@read_api