From e5a914c3c211d6125c66d1a871c5fe641b6559da Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 30 Dec 2020 11:37:26 -0800 Subject: [PATCH] Fixes API search causing 500 error --- bookwyrm/connectors/abstract_connector.py | 8 +++++++- bookwyrm/views.py | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/bookwyrm/connectors/abstract_connector.py b/bookwyrm/connectors/abstract_connector.py index fd2f8b3db..ae73f75e1 100644 --- a/bookwyrm/connectors/abstract_connector.py +++ b/bookwyrm/connectors/abstract_connector.py @@ -1,6 +1,6 @@ ''' functionality outline for a book data connector ''' from abc import ABC, abstractmethod -from dataclasses import dataclass +from dataclasses import asdict, dataclass import logging from urllib3.exceptions import RequestError @@ -241,6 +241,12 @@ class SearchResult: return "".format( self.key, self.title, self.author) + def json(self): + ''' serialize a connector for json response ''' + serialized = asdict(self) + del serialized['connector'] + return serialized + class Mapping: ''' associate a local database field with a field in an external dataset ''' diff --git a/bookwyrm/views.py b/bookwyrm/views.py index 1afb82669..bd8948062 100644 --- a/bookwyrm/views.py +++ b/bookwyrm/views.py @@ -210,7 +210,7 @@ def search(request): if is_api_request(request): # only return local book results via json so we don't cause a cascade book_results = books_manager.local_search(query) - return JsonResponse([r.__dict__ for r in book_results], safe=False) + return JsonResponse([r.json() for r in book_results], safe=False) # use webfinger for mastodon style account@domain.com username if re.match(regex.full_username, query):