[fix] engine: wikidata - initialization fails with KeyError (#5993)

The response to QUERY_PROPERTY_NAMES has changed; fields without the `name`
field are now also returned.

Closes: https://github.com/searxng/searxng/issues/5982

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
Markus Heiser
2026-04-19 09:35:13 +02:00
committed by Markus Heiser
parent d501b0420a
commit 8fabaf86b6
+5 -2
View File
@@ -802,8 +802,11 @@ def init(engine_settings=None): # pylint: disable=unused-argument
query = QUERY_PROPERTY_NAMES.replace('%ATTRIBUTES%', " ".join(wikidata_property_names)) query = QUERY_PROPERTY_NAMES.replace('%ATTRIBUTES%', " ".join(wikidata_property_names))
jsonresponse = send_wikidata_query(query, timeout=20) jsonresponse = send_wikidata_query(query, timeout=20)
for result in jsonresponse.get('results', {}).get('bindings', {}): for result in jsonresponse.get('results', {}).get('bindings', {}):
name = result['name']['value'] name_field = result.get("name")
lang = result['name']['xml:lang'] if not name_field:
continue
name = name_field["value"]
lang = name_field["xml:lang"]
entity_id = result['item']['value'].replace('http://www.wikidata.org/entity/', '') entity_id = result['item']['value'].replace('http://www.wikidata.org/entity/', '')
WIKIDATA_PROPERTIES[(entity_id, lang)] = name.capitalize() WIKIDATA_PROPERTIES[(entity_id, lang)] = name.capitalize()