[fix] engines: wikidata, no list as content when an entity has no description (#6824)

Wikidata kept showing up in `unresponsive_engines` as "unexpected crash", but only for some queries (`!wikidata loi anti gaspillage` for instance).

In `get_results`, `itemDescription` defaults to `[]`. When an entity has no description and `display_type` contains `"list"`, that empty list goes out as the `content` of a list result, and `ResultContainer.extend` fails with `TypeError: expected string or bytes-like object, got 'list'`. Every wikidata result of the query is dropped with it.

The default is now an empty string. `len(infobox_content) == 0` still works, and the infobox branch already expected a string.

`tests/unit/test_engine_wikidata.py` covers an entity with no description, once with `display_type` `["list"]` and once with `["infobox"]`. Without the fix both tests fail (`'content': []` instead of `''`), with it both pass.




itemDescription defaulted to [] in get_results. With "list" in display_type, that empty list was sent as the content of a list result and ResultContainer.extend raised a TypeError, so the whole wikidata answer of the query was lost. Default to an empty string instead.

Signed-off-by: Guillaume PUTIER <putier.guillaume@gmail.com>
Co-authored-by: Guillaume PUTIER <putier.guillaume@gmail.com>
This commit is contained in:
Guillaume P.
2026-10-07 11:18:19 +02:00
committed by GitHub
co-authored by Guillaume PUTIER
parent d48c4b5554
commit 6671d89bed
2 changed files with 28 additions and 1 deletions
+1 -1
View File
@@ -167,7 +167,7 @@ def get_results(
infobox_id_lang: str | None = None
infobox_urls: list[dict[str, str]] = []
infobox_attributes: list[dict[str, str]] = []
infobox_content = attribute_result.get("itemDescription", [])
infobox_content: str = attribute_result.get("itemDescription", "")
img_src: str | None = None
img_src_priority = 0
+27
View File
@@ -0,0 +1,27 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
# pylint: disable=missing-module-docstring,disable=missing-class-docstring
from unittest.mock import patch
from searx.engines import wikidata
from searx.wikidata_properties import get_attributes
from tests import SearxTestCase
class WikidataGetResultsTests(SearxTestCase):
ITEM = "http://www.wikidata.org/entity/Q1"
def test_no_desc_list(self):
# an entity without "itemDescription" must not leak a list into "content"
attribute_result = {"item": self.ITEM, "itemLabel": "Label"}
with patch.object(wikidata, "display_type", ["list"]):
results = wikidata.get_results(attribute_result, get_attributes("en"), "en")
self.assertEqual(results, [{"url": self.ITEM, "title": "Label", "content": ""}])
def test_no_desc_infobox(self):
attribute_result = {"item": self.ITEM, "itemLabel": "Label"}
with patch.object(wikidata, "display_type", ["infobox"]):
results = wikidata.get_results(attribute_result, get_attributes("en"), "en")
self.assertEqual(len(results), 1)
self.assertEqual(results[0]["content"], "")