2 Commits

Author SHA1 Message Date
Fabian Freund ed5955a5c7 [fix] Result.defaults_from() inverted logic (#6019)
The bug was introduced in commit 8769b7c6d (typification of result items); this
patch fixes the bug and also addresses the peculiarity that fields can be set
but contain no *usable* value:

If a field is set (exists) but contains an empty string or the value ``None``,
it is also considered *not set*. This also ensures that an integer 0 is
evaluated *as set*!

Co-Authored: Markus Heiser <markus.heiser@darmarit.de>
2026-04-28 17:42:29 +02:00
github-actions[bot] a7ac696b4a [l10n] update translations from Weblate (#6015)
54de6653b - 2026-04-15 - AndersNordh <andersnordh@noreply.codeberg.org>
e410bed58 - 2026-04-15 - AndersNordh <andersnordh@noreply.codeberg.org>

Co-authored-by: searxng-bot <searxng-bot@users.noreply.github.com>
2026-04-24 15:08:49 +02:00
5 changed files with 20 additions and 18 deletions
+13 -11
View File
@@ -32,7 +32,7 @@ import msgspec
from searx import logger as log
WHITESPACE_REGEX = re.compile('( |\t|\n)+', re.M | re.U)
UNKNOWN = object()
UNSET = object()
def _normalize_url_fields(result: "Result | LegacyResult"):
@@ -326,12 +326,13 @@ class Result(msgspec.Struct, kw_only=True):
def defaults_from(self, other: "Result"):
"""Fields not set in *self* will be updated from the field values of the
*other*.
*other*. If a field is set (exists) but contains an empty string
or the value ``None``, it is also considered *not set*.
"""
for field_name in self.__struct_fields__:
self_val = getattr(self, field_name, False)
other_val = getattr(other, field_name, False)
if self_val:
self_val = getattr(self, field_name, UNSET)
other_val = getattr(other, field_name, UNSET)
if self_val is UNSET and other_val not in (UNSET, "", None):
setattr(self, field_name, other_val)
@@ -440,8 +441,6 @@ class LegacyResult(dict[str, t.Any]):
Do not use this class in your own implementations!
"""
UNSET: object = object()
# emulate field types from type class Result
url: str | None
template: str
@@ -512,7 +511,7 @@ class LegacyResult(dict[str, t.Any]):
)
def __getattr__(self, name: str, default: t.Any = UNSET) -> t.Any:
if default == self.UNSET and name not in self:
if default == UNSET and name not in self:
raise AttributeError(f"LegacyResult object has no field named: {name}")
return self[name]
@@ -563,9 +562,12 @@ class LegacyResult(dict[str, t.Any]):
self.engines.add(self.engine)
def defaults_from(self, other: "LegacyResult"):
for k, v in other.items():
if not self.get(k):
self[k] = v
# If a field is set (exists) but contains an empty string or the value
# ``None``, it is also considered *not set*.
for field_name, other_val in other.items():
self_val = self.get(field_name, UNSET)
if self_val is UNSET and other_val not in ("", UNSET):
self[field_name] = other_val
def filter_urls(self, filter_func: "Callable[[Result | LegacyResult, str, str], str | bool]"):
"""See :py:obj:`Result.filter_urls`"""
Binary file not shown.
@@ -20,7 +20,7 @@ msgstr ""
"Project-Id-Version: searx\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2026-03-24 18:43+0000\n"
"PO-Revision-Date: 2026-04-09 18:57+0000\n"
"PO-Revision-Date: 2026-04-16 06:57+0000\n"
"Last-Translator: AndersNordh <andersnordh@noreply.codeberg.org>\n"
"Language-Team: Danish <https://translate.codeberg.org/projects/searxng/"
"searxng/da/>\n"
@@ -29,7 +29,7 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 5.16.2\n"
"X-Generator: Weblate 5.17\n"
"Generated-By: Babel 2.18.0\n"
#. CONSTANT_NAMES['NO_SUBGROUPING']
@@ -885,7 +885,7 @@ msgstr "Indstillinger"
#: searx/templates/simple/base.html:68
msgid "Powered by"
msgstr "Leveret af"
msgstr "Drevet af"
#: searx/templates/simple/base.html:68
msgid "a privacy-respecting, open metasearch engine"
Binary file not shown.
@@ -38,8 +38,8 @@ msgstr ""
"Project-Id-Version: searx\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2026-03-24 18:43+0000\n"
"PO-Revision-Date: 2026-03-27 07:33+0000\n"
"Last-Translator: bittin <bittin@noreply.codeberg.org>\n"
"PO-Revision-Date: 2026-04-16 06:57+0000\n"
"Last-Translator: AndersNordh <andersnordh@noreply.codeberg.org>\n"
"Language-Team: Swedish <https://translate.codeberg.org/projects/searxng/"
"searxng/sv/>\n"
"Language: sv\n"
@@ -47,7 +47,7 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 5.16.2\n"
"X-Generator: Weblate 5.17\n"
"Generated-By: Babel 2.18.0\n"
#. CONSTANT_NAMES['NO_SUBGROUPING']
@@ -903,7 +903,7 @@ msgstr "Inställningar"
#: searx/templates/simple/base.html:68
msgid "Powered by"
msgstr "Drivet av"
msgstr "Drivs av"
#: searx/templates/simple/base.html:68
msgid "a privacy-respecting, open metasearch engine"