Commit c9b7e6f9 authored by Denis Laxalde's avatar Denis Laxalde
Browse files

Properly handle labels without a "lang" in graph_extentities()

Previously, the "lang" value could be None because of getattr(...,
None). Subsequent usages of this value do not look quite right
(e.g. str(None) or set([None])). Instead, we now catch attribute error
and build the md5hash without the None value as well as insert an empty
set for language_code attribute when importing a label.

This also prepares for upgrade to python3.
parent 12b9a98f6645
......@@ -181,12 +181,20 @@ def graph_extentities(graph):
for rtype in label_rtypes:
kind = rtype.split('_', 1)[0] # drop '_label' suffix
for label in extentity.values.pop(rtype):
lang = getattr(label, 'lang', None)
md5hash = md5(str(lang) + label.encode('utf-8'))
md5hash = md5()
language_code = set()
lang = label.lang
except AttributeError:
labelid = str(extentity.extid) + '#' + rtype + md5hash.hexdigest()
labels.append(ExtEntity('Label', labelid,
{'label': set([label]),
'language_code': set([lang]),
'language_code': language_code,
'kind': set([kind]),
'label_of': set([extentity.extid])}))
# yield extentity before labels since it must be handled first in case the ExternalUri
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment