mirror of
https://github.com/searxng/searxng.git
synced 2025-08-03 10:32:21 +02:00
[fix] JSON & CSV format return error 500
For CSV and JSON output, the LegacyResult and the Result objects needs to be converted to a python dictionary. Closes: https://github.com/searxng/searxng/issues/4244 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
parent
906b9e7d4c
commit
df3344e5d5
2 changed files with 15 additions and 10 deletions
|
@ -110,6 +110,9 @@ class Result(msgspec.Struct, kw_only=True):
|
|||
|
||||
return iter(self.__struct_fields__)
|
||||
|
||||
def as_dict(self):
|
||||
return {f: getattr(self, f) for f in self.__struct_fields__}
|
||||
|
||||
|
||||
class LegacyResult(dict):
|
||||
"""A wrapper around a legacy result item. The SearXNG core uses this class
|
||||
|
@ -130,10 +133,12 @@ class LegacyResult(dict):
|
|||
UNSET = object()
|
||||
WHITESPACE_REGEX = re.compile('( |\t|\n)+', re.M | re.U)
|
||||
|
||||
def as_dict(self):
|
||||
return self
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
||||
super().__init__(*args, **kwargs)
|
||||
self.__dict__ = self
|
||||
|
||||
# Init fields with defaults / compare with defaults of the fields in class Result
|
||||
self.engine = self.get("engine", "")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue