Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when searching on front page #136

Open
bellisk opened this issue Apr 19, 2024 · 2 comments
Open

Error when searching on front page #136

bellisk opened this issue Apr 19, 2024 · 2 comments
Labels
bug Something isn't working documentation Improvements or additions to documentation reviewed v0.6.0

Comments

@bellisk
Copy link
Contributor

bellisk commented Apr 19, 2024

Describe the bug
Typing into the search box on the front page produces an error (in debug mode, this looks quite gnarly - see screenshot below). Hitting enter to run the search leads to an error page.

To Reproduce

  1. Deploy Ourchive to VPS hosting as described in https://docs.getourchive.io/admin-getting-started/
  2. Run with OURCHIVE_DEBUG=True in .env
  3. On the front page, type a search term in the search box
  4. See that a narrow rectangle appears beside the search box, showing debug information in it - I guess this is where a list of suggestions should be shown
  5. Hit enter to run the search
  6. See that the url http://example.org/search/ is loaded and shows an error page

Expected behavior
Typing in the search box should show a dynamically loaded list of search suggestions. Hitting enter should take you to a page with a list of results for your search term.

Screenshots
Error displayed while typing into the search box:
Screenshot 2024-04-19 at 23-40-46 Ourchive

Desktop (please complete the following information):

  • OS: Linux Mint
  • Browser: Firefox
  • Version: 124

Hosting
Digital Ocean droplet running Ubuntu 22.04.

Additional context
Logs from typing into the search box:

urllib3.connectionpool DEBUG 2024-04-19 18:50:54,002 connectionpool 14729 139836490721504 http://example.org:80 "GET /api/tag-autocomplete?term=fo&type=&fetch_all= HTTP/1.1" 308 180
urllib3.connectionpool DEBUG 2024-04-19 18:50:54,004 connectionpool 14729 139836490721504 Starting new HTTPS connection (1): example.org:443
api.custom_exception_handler WARNING 2024-04-19 18:50:54,092 custom_exception_handler 14730 139836497751040 operator does not exist: unknown <<-> character varying
LINE 1: ...tag"."filterable", "api_tag"."tag_type_id", ('fo' <<-> "api_...
                                                             ^
HINT:  No operator matches the given name and argument types. You might need to add explicit type casts.

django.request ERROR 2024-04-19 18:50:54,136 log 14730 139836497751040 Internal Server Error: /api/tag-autocomplete
Traceback (most recent call last):
  File "/home/ourchive/ourchive/virtualenv/lib/python3.10/site-packages/django/db/backends/utils.py", line 105, in _execute
    return self.cursor.execute(sql, params)
psycopg2.errors.UndefinedFunction: operator does not exist: unknown <<-> character varying
LINE 1: ...tag"."filterable", "api_tag"."tag_type_id", ('fo' <<-> "api_...
                                                             ^
HINT:  No operator matches the given name and argument types. You might need to add explicit type casts.


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/ourchive/ourchive/virtualenv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "/home/ourchive/ourchive/virtualenv/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/ourchive/ourchive/virtualenv/lib/python3.10/site-packages/django/views/decorators/csrf.py", line 65, in _view_wrapper
    return view_func(request, *args, **kwargs)
  File "/home/ourchive/ourchive/virtualenv/lib/python3.10/site-packages/django/views/generic/base.py", line 104, in view
    return self.dispatch(request, *args, **kwargs)
  File "/home/ourchive/ourchive/virtualenv/lib/python3.10/site-packages/rest_framework/views.py", line 509, in dispatch
    response = self.handle_exception(exc)
  File "/home/ourchive/ourchive/virtualenv/lib/python3.10/site-packages/rest_framework/views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/home/ourchive/ourchive/virtualenv/lib/python3.10/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
    raise exc
  File "/home/ourchive/ourchive/virtualenv/lib/python3.10/site-packages/rest_framework/views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
  File "/home/ourchive/ourchive/ourchive_app/api/views.py", line 122, in get
    results = searcher.do_tag_search(request.GET.get(
  File "/home/ourchive/ourchive/ourchive_app/api/search/search_service.py", line 47, in do_tag_search
    results = self.searcher.autocomplete_tags(term, tag_type, fetch_all)
  File "/home/ourchive/ourchive/ourchive_app/api/search/search.py", line 438, in autocomplete_tags
    for result in resultset:
  File "/home/ourchive/ourchive/virtualenv/lib/python3.10/site-packages/django/db/models/query.py", line 400, in __iter__
    self._fetch_all()
  File "/home/ourchive/ourchive/virtualenv/lib/python3.10/site-packages/django/db/models/query.py", line 1928, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "/home/ourchive/ourchive/virtualenv/lib/python3.10/site-packages/django/db/models/query.py", line 91, in __iter__
    results = compiler.execute_sql(
  File "/home/ourchive/ourchive/virtualenv/lib/python3.10/site-packages/django/db/models/sql/compiler.py", line 1562, in execute_sql
    cursor.execute(sql, params)
  File "/home/ourchive/ourchive/virtualenv/lib/python3.10/site-packages/django/db/backends/utils.py", line 122, in execute
    return super().execute(sql, params)
  File "/home/ourchive/ourchive/virtualenv/lib/python3.10/site-packages/django/db/backends/utils.py", line 79, in execute
    return self._execute_with_wrappers(
  File "/home/ourchive/ourchive/virtualenv/lib/python3.10/site-packages/django/db/backends/utils.py", line 92, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/home/ourchive/ourchive/virtualenv/lib/python3.10/site-packages/django/db/backends/utils.py", line 100, in _execute
    with self.db.wrap_database_errors:
  File "/home/ourchive/ourchive/virtualenv/lib/python3.10/site-packages/django/db/utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/home/ourchive/ourchive/virtualenv/lib/python3.10/site-packages/django/db/backends/utils.py", line 105, in _execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: operator does not exist: unknown <<-> character varying
LINE 1: ...tag"."filterable", "api_tag"."tag_type_id", ('fo' <<-> "api_...
                                                             ^
HINT:  No operator matches the given name and argument types. You might need to add explicit type casts.

urllib3.connectionpool DEBUG 2024-04-19 18:50:54,142 connectionpool 14729 139836490721504 https://example.org:443 "GET /api/tag-autocomplete?term=fo&type=&fetch_all= HTTP/1.1" 500 153238
django.request ERROR 2024-04-19 18:50:54,198 log 14729 139836490721504 Internal Server Error: /tag-autocomplete
Traceback (most recent call last):
  File "/home/ourchive/ourchive/virtualenv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "/home/ourchive/ourchive/virtualenv/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/ourchive/ourchive/ourchive_app/frontend/views.py", line 575, in tag_autocomplete
    tags = response.response_data['results']
KeyError: 'results'

Logs from hitting enter to carry out the search:

urllib3.connectionpool DEBUG 2024-04-19 21:51:58,722 connectionpool 20981 140278402814560 https://example.org:443 "POST /api/search/ HTTP/1.1" 500 170833
frontend.searcher DEBUG 2024-04-19 21:51:58,730 searcher 20981 140278402814560 Search response data: {}
django.request ERROR 2024-04-19 21:51:58,774 log 20981 140278402814560 Internal Server Error: /search/
Traceback (most recent call last):
  File "/home/ourchive/ourchive/virtualenv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "/home/ourchive/ourchive/virtualenv/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/ourchive/ourchive/ourchive_app/frontend/views.py", line 555, in search
    template_data = build_and_execute_search(request)
  File "/home/ourchive/ourchive/ourchive_app/frontend/searcher.py", line 302, in build_and_execute_search
    'include_facets': facets[0],
KeyError: 0
@c-e-p
Copy link
Collaborator

c-e-p commented Apr 22, 2024

@bellisk Oh wow, this is a dependency I installed too long ago that I'm not sure we documented.

You can fix this by installing the trigram function: https://dba.stackexchange.com/a/246124

I was able to reproduce this error on the front page and when searching from the top search bar, because in both cases the trigram function is being called.

We'll update documentation for this.

@c-e-p c-e-p added bug Something isn't working documentation Improvements or additions to documentation labels Apr 22, 2024
@bellisk
Copy link
Contributor Author

bellisk commented Apr 23, 2024

I installed the trigram function and now it works, awesome!

@c-e-p c-e-p added the reviewed label May 9, 2024
@c-e-p c-e-p added the v0.6.0 label Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation reviewed v0.6.0
Projects
None yet
Development

No branches or pull requests

2 participants