Calibre-web AttributeError: 'NoneType' object has no attribute 'query'

Hello everyone! I was hoping to use calibre-web image on a Synology NAS, but after starting container and setting up the database, I continuously get this error from the UI: AttributeError: 'NoneType' object has no attribute 'query'

I found this issue in the app repository where the creator state that the error is due to the dockerisation and is not due to the app itself: [Docker] AttributeError: 'NoneType' object has no attribute 'query' · Issue #2231 · janeczku/calibre-web · GitHub
This issue, duplicated of the first with slightly more details: Unable to access webui, running on unraid docker container · Issue #2380 · janeczku/calibre-web · GitHub

It seems the issue lies in permissions around accessing the metadata database.

This is the screenshot:

This is the stacktrace:

Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 2073, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1518, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1516, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1502, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
File "/app/calibre-web/cps/usermanagement.py", line 35, in decorated_view
return login_required(func)(*args, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/flask_login/utils.py", line 303, in decorated_view
return current_app.ensure_sync(func)(*args, **kwargs)
File "/app/calibre-web/cps/web.py", line 781, in index
return render_books_list("newest", sort_param, 1, page)
File "/app/calibre-web/cps/web.py", line 399, in render_books_list
entries, random, pagination = calibre_db.fill_indexpage(page, 0, db.Books, True, order[0],
File "/app/calibre-web/cps/db.py", line 730, in fill_indexpage
return self.fill_indexpage_with_archived_books(page, database, pagesize, db_filter, order, False,
File "/app/calibre-web/cps/db.py", line 737, in fill_indexpage_with_archived_books
random_query = self.generate_linked_query(config_read_column, database)
File "/app/calibre-web/cps/db.py", line 691, in generate_linked_query
query = (self.session.query(database, ub.ArchivedBook.is_archived, ub.ReadBook.read_status)
AttributeError: 'NoneType' object has no attribute 'query'

There are no errors in the logs, the calibre DB is correctly mounted in the /books, where I see the metadata.db file:

root@linuxserver-calibre-web1:/books# file metadata.db                                                                                                                                                      
metadata.db: SQLite 3.x database, user version 22, last written using SQLite version 3011000       

Any idea what could be wrong here?

you would need to provide your docker compose or docker run (the syno gui for docker is very bad and can cause issues) and container logs (how to get container logs is in the container readme)