Skip to content

Commit

Permalink
Fix broken template rendering on /search requests (internetarchive#8757)
Browse files Browse the repository at this point in the history
* Fix broken template rendering on /search requests

Work search template expects a SearchResponse object,
but None was being sent if the request did not have any params.
Updated request to always send a SearchResponse object.

Also, removed an unused import.
  • Loading branch information
ddominguez authored and Achorn committed Mar 14, 2024
1 parent 9fcdf04 commit d74477b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions openlibrary/plugins/worksearch/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from openlibrary.core import cache
from openlibrary.core.lending import add_availability
from openlibrary.core.models import Edition
from openlibrary.plugins.inside.code import fulltext_search
from openlibrary.plugins.openlibrary.processors import urlsafe
from openlibrary.plugins.upstream.utils import (
get_language_name,
Expand Down Expand Up @@ -491,11 +490,14 @@ def GET(self):
page = int(param.get('page', 1))
sort = param.get('sort', None)
rows = 20
search_response: SearchResponse | None = None
if param:
search_response = do_search(
param, sort, page, rows=rows, spellcheck_count=3
)
else:
search_response = SearchResponse(
facet_counts=None, sort='', docs=[], num_found=0, solr_select=''
)
return render.work_search(
' '.join(q_list),
search_response,
Expand Down

0 comments on commit d74477b

Please sign in to comment.