whiskyechobravo / kerkoapp

A web application that provides a faceted search interface for bibliographies managed with Zotero.
https://whiskyechobravo.github.io/kerko/
BSD 3-Clause "New" or "Revised" License
68 stars 24 forks source link

KeyError: "No field named 'collection_facet_F3B5WRMF'" #27

Closed remillc closed 2 years ago

remillc commented 2 years ago

Hi,

I'm running Kerkoapp in a Docker container following the readme instructions on a Windows 10 station. The Kerkoapp app runs well with the defaults settings. The problem comes when I add a KERKOAPP_COLLECTION_FACETS variable to the .env file. There, the app shows an error page:

2022-10-26 15-36-22

Configs

Here are the infos to help reproduce the problem. It is a test library so I include the Zoreto API key:

Library: https://www.zotero.org/groups/4833782/test-remillc-2/library

.env file:

SECRET_KEY=ZWehodY9u0N4LHWNrLhy
KERKO_TITLE=Test
KERKO_ZOTERO_API_KEY=njNkHhi4RNsu5QK1ZqdZK6Dl
KERKO_ZOTERO_LIBRARY_ID=4833782
KERKO_ZOTERO_LIBRARY_TYPE=group
KERKO_PRINT_ITEM_LINK=True
KERKO_PRINT_CITATIONS_LINK=True

# KerkoApp variables.
FLASK_APP=kerkoapp.py
FLASK_ENV=production

# Docker container variables.
MODULE_NAME=kerkoapp

KERKOAPP_COLLECTION_FACETS=F3B5WRMF:1:Organismes
# LOGGING_LEVEL=DEBUG

The API key is set for a Read/Write access to the test-remillc-2 group.

Here is a full log:

D:\projets\kerkoapp-docker
λ make run
docker run --env-file D:/projets/kerkoapp-docker/.env --rm -p 8080:80 -v D:/projets/kerkoapp-docker/data:/app/data -v /tmp/kerkoapp-dev-log:/dev/log whiskyechobravo/kerkoapp
Checking for script in /app/prestart.sh
Running script /app/prestart.sh
Running inside /app/prestart.sh, you could add migrations to this file, e.g.:

#! /usr/bin/env bash

# Let the DB start
sleep 10;
# Run migrations
alembic upgrade head

[2022-10-26 19:34:01 +0000] [1] [INFO] Starting gunicorn 20.1.0
[2022-10-26 19:34:01 +0000] [1] [INFO] Listening at: http://0.0.0.0:80 (1)
[2022-10-26 19:34:01 +0000] [1] [INFO] Using worker: egg:meinheld#gunicorn_worker
[2022-10-26 19:34:01 +0000] [7] [INFO] Booting worker with pid: 7
[2022-10-26 19:34:01 +0000] [8] [INFO] Booting worker with pid: 8
[2022-10-26 19:34:02 +0000] [9] [INFO] Booting worker with pid: 9
[2022-10-26 19:34:02 +0000] [10] [INFO] Booting worker with pid: 10
[2022-10-26 19:34:02 +0000] [11] [INFO] Booting worker with pid: 11
[2022-10-26 19:34:02 +0000] [12] [INFO] Booting worker with pid: 12
[2022-10-26 19:34:02 +0000] [13] [INFO] Booting worker with pid: 13
[2022-10-26 19:34:02 +0000] [14] [INFO] Booting worker with pid: 14
--- Logging error ---
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2073, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1518, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1516, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1502, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "/usr/local/lib/python3.9/site-packages/kerko/exceptions.py", line 20, in wrapper
    return wrapped(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/kerko/views.py", line 46, in search
    search_results, facet_results, total_count, page_count, last_sync = query.run_query(
  File "/usr/local/lib/python3.9/site-packages/kerko/query.py", line 372, in run_query
    results = searcher.search_page(q, **search_args)
  File "/usr/local/lib/python3.9/site-packages/whoosh/searching.py", line 639, in search_page
    results = self.search(query, limit=pagenum * pagelen, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/whoosh/searching.py", line 786, in search
    self.search_with_collector(q, c)
  File "/usr/local/lib/python3.9/site-packages/whoosh/searching.py", line 817, in search_with_collector
    collector.prepare(self, q, context)
  File "/usr/local/lib/python3.9/site-packages/whoosh/collectors.py", line 699, in prepare
    self.child.prepare(top_searcher, q, context)
  File "/usr/local/lib/python3.9/site-packages/whoosh/collectors.py", line 805, in prepare
    ctr = facet.categorizer(top_searcher)
  File "/usr/local/lib/python3.9/site-packages/whoosh/sorting.py", line 197, in categorizer
    fieldobj = global_searcher.schema[fieldname]
  File "/usr/local/lib/python3.9/site-packages/whoosh/fields.py", line 1385, in __getitem__
    raise KeyError("No field named %r" % (name,))
KeyError: "No field named 'collection_facet_F3B5WRMF'"

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/logging/handlers.py", line 954, in emit
    self.socket.send(msg)
OSError: [Errno 9] Bad file descriptor

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/logging/handlers.py", line 875, in _connect_unixsocket
    self.socket.connect(address)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/logging/handlers.py", line 957, in emit
    self._connect_unixsocket(self.address)
  File "/usr/local/lib/python3.9/logging/handlers.py", line 886, in _connect_unixsocket
    self.socket.connect(address)
ConnectionRefusedError: [Errno 111] Connection refused
Call stack:
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2091, in __call__
    return self.wsgi_app(environ, start_response)
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2076, in wsgi_app
    response = self.handle_exception(e)
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1434, in handle_exception
    self.log_exception(exc_info)
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1457, in log_exception
    self.logger.error(
Message: 'Exception on /bibliography/ [GET]'
Arguments: ()
[2022-10-26 19:34:04,427] ERROR in app: Exception on /bibliography/ [GET]
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2073, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1518, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1516, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1502, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "/usr/local/lib/python3.9/site-packages/kerko/exceptions.py", line 20, in wrapper
    return wrapped(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/kerko/views.py", line 46, in search
    search_results, facet_results, total_count, page_count, last_sync = query.run_query(
  File "/usr/local/lib/python3.9/site-packages/kerko/query.py", line 372, in run_query
    results = searcher.search_page(q, **search_args)
  File "/usr/local/lib/python3.9/site-packages/whoosh/searching.py", line 639, in search_page
    results = self.search(query, limit=pagenum * pagelen, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/whoosh/searching.py", line 786, in search
    self.search_with_collector(q, c)
  File "/usr/local/lib/python3.9/site-packages/whoosh/searching.py", line 817, in search_with_collector
    collector.prepare(self, q, context)
  File "/usr/local/lib/python3.9/site-packages/whoosh/collectors.py", line 699, in prepare
    self.child.prepare(top_searcher, q, context)
  File "/usr/local/lib/python3.9/site-packages/whoosh/collectors.py", line 805, in prepare
    ctr = facet.categorizer(top_searcher)
  File "/usr/local/lib/python3.9/site-packages/whoosh/sorting.py", line 197, in categorizer
    fieldobj = global_searcher.schema[fieldname]
  File "/usr/local/lib/python3.9/site-packages/whoosh/fields.py", line 1385, in __getitem__
    raise KeyError("No field named %r" % (name,))
KeyError: "No field named 'collection_facet_F3B5WRMF'"
--- Logging error ---
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2073, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1518, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1516, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1502, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "/usr/local/lib/python3.9/site-packages/kerko/exceptions.py", line 20, in wrapper
    return wrapped(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/kerko/views.py", line 46, in search
    search_results, facet_results, total_count, page_count, last_sync = query.run_query(
  File "/usr/local/lib/python3.9/site-packages/kerko/query.py", line 372, in run_query
    results = searcher.search_page(q, **search_args)
  File "/usr/local/lib/python3.9/site-packages/whoosh/searching.py", line 639, in search_page
    results = self.search(query, limit=pagenum * pagelen, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/whoosh/searching.py", line 786, in search
    self.search_with_collector(q, c)
  File "/usr/local/lib/python3.9/site-packages/whoosh/searching.py", line 817, in search_with_collector
    collector.prepare(self, q, context)
  File "/usr/local/lib/python3.9/site-packages/whoosh/collectors.py", line 699, in prepare
    self.child.prepare(top_searcher, q, context)
  File "/usr/local/lib/python3.9/site-packages/whoosh/collectors.py", line 805, in prepare
    ctr = facet.categorizer(top_searcher)
  File "/usr/local/lib/python3.9/site-packages/whoosh/sorting.py", line 197, in categorizer
    fieldobj = global_searcher.schema[fieldname]
  File "/usr/local/lib/python3.9/site-packages/whoosh/fields.py", line 1385, in __getitem__
    raise KeyError("No field named %r" % (name,))
KeyError: "No field named 'collection_facet_F3B5WRMF'"

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/logging/handlers.py", line 954, in emit
    self.socket.send(msg)
OSError: [Errno 9] Bad file descriptor

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/logging/handlers.py", line 875, in _connect_unixsocket
    self.socket.connect(address)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/logging/handlers.py", line 957, in emit
    self._connect_unixsocket(self.address)
  File "/usr/local/lib/python3.9/logging/handlers.py", line 886, in _connect_unixsocket
    self.socket.connect(address)
ConnectionRefusedError: [Errno 111] Connection refused
Call stack:
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2091, in __call__
    return self.wsgi_app(environ, start_response)
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2076, in wsgi_app
    response = self.handle_exception(e)
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1434, in handle_exception
    self.log_exception(exc_info)
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1457, in log_exception
    self.logger.error(
Message: 'Exception on /bibliography/ [GET]'
Arguments: ()

Hoping to find some help!

Christian

davidlesieur commented 2 years ago

Adding new facets require changes to the format of Kerko's database. Thus, your issue is likely to be fixed after running make kerkoclean && make kerkosync. If not, please let us know here.

The upcoming Kerko will output more useful error messages for this type of problem!

remillc commented 2 years ago

It worked, thanks!

For info, the kerkoapp isn't installed in a docker. We used a python virtual environment behind a WSGI server. So the command I used was ../bin/flask kerko clean and ../bin/flask kerko sync from the kerkoapp folder.