janeczku / calibre-web

:books: Web app for browsing, reading and downloading eBooks stored in a Calibre database
GNU General Public License v3.0
13.13k stars 1.4k forks source link

Error 500 every morning #3156

Closed maxsmooth closed 2 months ago

maxsmooth commented 2 months ago

Describe the bug/problem

After upgrade to v0.6.23 i find error 500 after login. If i restart container i works well until next morning. Here is what browser shows:

Calibre-Web
500 Internal Server Error
The server encountered an internal error and was unable to complete your request. There is an error in the application.
Traceback (most recent call last):
File "/app/calibre-web/cps/db.py", line 786, in generate_linked_query
query = (self.session.query(database, ub.ArchivedBook.is_archived, read_column.value)
AttributeError: 'NoneType' object has no attribute 'query'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/lsiopy/lib/python3.10/site-packages/flask/app.py", line 1473, in wsgi_app
response = self.full_dispatch_request()
File "/lsiopy/lib/python3.10/site-packages/flask/app.py", line 882, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/lsiopy/lib/python3.10/site-packages/flask/app.py", line 880, in full_dispatch_request
rv = self.dispatch_request()
File "/lsiopy/lib/python3.10/site-packages/flask/app.py", line 865, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return]
File "/app/calibre-web/cps/usermanagement.py", line 97, in decorated_view
return login_required(func)(*args, **kwargs)
File "/app/calibre-web/cps/cw_login/utils.py", line 296, in decorated_view
return current_app.ensure_sync(func)(*args, **kwargs)
File "/app/calibre-web/cps/web.py", line 807, in index
return render_books_list("newest", sort_param, 1, page)
File "/app/calibre-web/cps/web.py", line 413, 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 818, 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 832, in fill_indexpage_with_archived_books
query = self.generate_linked_query(config_read_column, database)
File "/app/calibre-web/cps/db.py", line 792, in generate_linked_query
query = self.session.query(database, None, ub.ArchivedBook.is_archived)
AttributeError: 'NoneType' object has no attribute 'query'

Logfile

[2024-09-20 04:00:00,002]  INFO {apscheduler.executors.default:123} Running job "backup metadata (trigger: cron[hour='4'], next run at: 2024-09-21 04:00:00 CEST)" (scheduled at 2024-09-20 04:00:00+02:00)
[2024-09-20 04:00:00,002]  INFO {apscheduler.executors.default:123} Running job "reconnect (trigger: cron[hour='4'], next run at: 2024-09-21 04:00:00 CEST)" (scheduled at 2024-09-20 04:00:00+02:00)
[2024-09-20 04:00:00,002]  INFO {apscheduler.executors.default:123} Running job "delete superfluous book covers (trigger: cron[hour='4'], next run at: 2024-09-21 04:00:00 CEST)" (scheduled at 2024-09-20 04:00:00+02:00)
[2024-09-20 04:00:00,004]  INFO {apscheduler.executors.default:123} Running job "delete temp (trigger: cron[hour='4'], next run at: 2024-09-21 04:00:00 CEST)" (scheduled at 2024-09-20 04:00:00+02:00)
[2024-09-20 04:00:00,004]  INFO {apscheduler.executors.default:123} Running job "generate book covers (trigger: cron[hour='4'], next run at: 2024-09-21 04:00:00 CEST)" (scheduled at 2024-09-20 04:00:00+02:00)
[2024-09-20 04:00:00,033]  INFO {apscheduler.executors.default:144} Job "reconnect (trigger: cron[hour='4'], next run at: 2024-09-21 04:00:00 CEST)" executed successfully
[2024-09-20 04:00:00,035]  INFO {apscheduler.executors.default:144} Job "backup metadata (trigger: cron[hour='4'], next run at: 2024-09-21 04:00:00 CEST)" executed successfully
[2024-09-20 04:00:00,037]  INFO {apscheduler.executors.default:144} Job "delete superfluous book covers (trigger: cron[hour='4'], next run at: 2024-09-21 04:00:00 CEST)" executed successfully
[2024-09-20 04:00:00,038]  INFO {apscheduler.executors.default:144} Job "generate book covers (trigger: cron[hour='4'], next run at: 2024-09-21 04:00:00 CEST)" executed successfully
[2024-09-20 04:00:00,038]  INFO {apscheduler.executors.default:144} Job "delete temp (trigger: cron[hour='4'], next run at: 2024-09-21 04:00:00 CEST)" executed successfully
[2024-09-20 04:00:06,469] ERROR {cps.services.worker:202} Set changed size during iteration
[2024-09-20 04:00:06,471] ERROR {cps.services.worker:202} local variable 'book' referenced before assignment
[2024-09-20 04:00:06,532] ERROR {cps.services.worker:202} (sqlite3.OperationalError) no such table: thumbnail
[SQL: SELECT thumbnail.id AS thumbnail_id, thumbnail.entity_id AS thumbnail_entity_id, thumbnail.uuid AS thumbnail_uuid, thumbnail.format AS thumbnail_format, thumbnail.type AS thumbnail_type, thumbnail.resolution AS thumbnail_resolution, thumbnail.file>
FROM thumbnail LEFT OUTER JOIN books ON thumbnail.entity_id = books.id
WHERE books.id IS NULL]
(Background on this error at: https://sqlalche.me/e/20/e3q8)
[2024-09-20 04:00:06,534] ERROR {cps.services.worker:202} (sqlite3.OperationalError) no such table: books
[SQL: SELECT books.id AS books_id, books.title AS books_title, books.sort AS books_sort, books.author_sort AS books_author_sort, books.timestamp AS books_timestamp, books.pubdate AS books_pubdate, books.series_index AS books_series_index, books.last_mod>
FROM books
WHERE books.has_cover = ?]
[parameters: (1,)]
(Background on this error at: https://sqlalche.me/e/20/e3q8)
[2024-09-20 04:55:00,000]  INFO {apscheduler.executors.default:123} Running job "end scheduled task (trigger: cron[hour='4', minute='55'], next run at: 2024-09-21 04:55:00 CEST)" (scheduled at 2024-09-20 04:55:00+02:00)
[2024-09-20 04:55:00,001]  INFO {apscheduler.executors.default:144} Job "end scheduled task (trigger: cron[hour='4', minute='55'], next run at: 2024-09-21 04:55:00 CEST)" executed successfully
[2024-09-20 11:16:38,547] ERROR {cps:838} Exception on /opds/stats [GET]
Traceback (most recent call last):
  File "/lsiopy/lib/python3.10/site-packages/flask/app.py", line 1473, in wsgi_app
    response = self.full_dispatch_request()
  File "/lsiopy/lib/python3.10/site-packages/flask/app.py", line 882, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/lsiopy/lib/python3.10/site-packages/flask/app.py", line 880, in full_dispatch_request
    rv = self.dispatch_request()
  File "/lsiopy/lib/python3.10/site-packages/flask/app.py", line 865, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
  File "/app/calibre-web/cps/usermanagement.py", line 82, in decorated
    return auth.ensure_sync(f)(*args, **kwargs)
  File "/app/calibre-web/cps/opds.py", line 453, in get_database_stats
    stat['books'] = calibre_db.session.query(db.Books).count()
AttributeError: 'NoneType' object has no attribute 'query'
[2024-09-20 11:16:42,067] ERROR {cps:838} Exception on /opds/stats [GET]
Traceback (most recent call last):
  File "/lsiopy/lib/python3.10/site-packages/flask/app.py", line 1473, in wsgi_app
    response = self.full_dispatch_request()
  File "/lsiopy/lib/python3.10/site-packages/flask/app.py", line 882, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/lsiopy/lib/python3.10/site-packages/flask/app.py", line 880, in full_dispatch_request
    rv = self.dispatch_request()
  File "/lsiopy/lib/python3.10/site-packages/flask/app.py", line 865, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
  File "/app/calibre-web/cps/usermanagement.py", line 82, in decorated
    return auth.ensure_sync(f)(*args, **kwargs)
  File "/app/calibre-web/cps/opds.py", line 453, in get_database_stats
    stat['books'] = calibre_db.session.query(db.Books).count()
AttributeError: 'NoneType' object has no attribute 'query'
[2024-09-20 11:17:21,816] ERROR {cps.db:790} Custom Column No.1 does not exist in calibre database
[2024-09-20 11:17:21,816] ERROR {cps:838} Exception on / [GET]
Traceback (most recent call last):
  File "/app/calibre-web/cps/db.py", line 786, in generate_linked_query
    query = (self.session.query(database, ub.ArchivedBook.is_archived, read_column.value)
AttributeError: 'NoneType' object has no attribute 'query'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/lsiopy/lib/python3.10/site-packages/flask/app.py", line 1473, in wsgi_app
    response = self.full_dispatch_request()
  File "/lsiopy/lib/python3.10/site-packages/flask/app.py", line 882, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/lsiopy/lib/python3.10/site-packages/flask/app.py", line 880, in full_dispatch_request
    rv = self.dispatch_request()
  File "/lsiopy/lib/python3.10/site-packages/flask/app.py", line 865, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
  File "/app/calibre-web/cps/usermanagement.py", line 97, in decorated_view
    return login_required(func)(*args, **kwargs)
  File "/app/calibre-web/cps/cw_login/utils.py", line 296, in decorated_view
    return current_app.ensure_sync(func)(*args, **kwargs)
  File "/app/calibre-web/cps/web.py", line 807, in index
    return render_books_list("newest", sort_param, 1, page)
  File "/app/calibre-web/cps/web.py", line 413, 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 818, 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 832, in fill_indexpage_with_archived_books
    query = self.generate_linked_query(config_read_column, database)
  File "/app/calibre-web/cps/db.py", line 792, in generate_linked_query
    query = self.session.query(database, None, ub.ArchivedBook.is_archived)
AttributeError: 'NoneType' object has no attribute 'query'
[2024-09-20 11:19:18,574] ERROR {cps:838} Exception on /opds/stats [GET]
Traceback (most recent call last):
  File "/lsiopy/lib/python3.10/site-packages/flask/app.py", line 1473, in wsgi_app
    response = self.full_dispatch_request()
  File "/lsiopy/lib/python3.10/site-packages/flask/app.py", line 882, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/lsiopy/lib/python3.10/site-packages/flask/app.py", line 880, in full_dispatch_request
    rv = self.dispatch_request()
  File "/lsiopy/lib/python3.10/site-packages/flask/app.py", line 865, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
  File "/app/calibre-web/cps/usermanagement.py", line 82, in decorated
    return auth.ensure_sync(f)(*args, **kwargs)
  File "/app/calibre-web/cps/opds.py", line 453, in get_database_stats
    stat['books'] = calibre_db.session.query(db.Books).count()
AttributeError: 'NoneType' object has no attribute 'query'
[2024-09-20 11:19:20,086] ERROR {cps.db:790} Custom Column No.1 does not exist in calibre database
[2024-09-20 11:19:20,086] ERROR {cps:838} Exception on / [GET]
Traceback (most recent call last):
  File "/app/calibre-web/cps/db.py", line 786, in generate_linked_query
    query = (self.session.query(database, ub.ArchivedBook.is_archived, read_column.value)
AttributeError: 'NoneType' object has no attribute 'query'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/lsiopy/lib/python3.10/site-packages/flask/app.py", line 1473, in wsgi_app
    response = self.full_dispatch_request()
  File "/lsiopy/lib/python3.10/site-packages/flask/app.py", line 882, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/lsiopy/lib/python3.10/site-packages/flask/app.py", line 880, in full_dispatch_request
    rv = self.dispatch_request()
  File "/lsiopy/lib/python3.10/site-packages/flask/app.py", line 865, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
  File "/app/calibre-web/cps/usermanagement.py", line 97, in decorated_view
    return login_required(func)(*args, **kwargs)
  File "/app/calibre-web/cps/cw_login/utils.py", line 296, in decorated_view
    return current_app.ensure_sync(func)(*args, **kwargs)
  File "/app/calibre-web/cps/web.py", line 807, in index
    return render_books_list("newest", sort_param, 1, page)
  File "/app/calibre-web/cps/web.py", line 413, 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 818, 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 832, in fill_indexpage_with_archived_books
    query = self.generate_linked_query(config_read_column, database)
  File "/app/calibre-web/cps/db.py", line 792, in generate_linked_query
    query = self.session.query(database, None, ub.ArchivedBook.is_archived)
AttributeError: 'NoneType' object has no attribute 'query'

Environment (please complete the following information):

OzzieIsaacs commented 2 months ago

Your library database isn't available. A typical docker problem, I don't know why. Please ask for help from the docker provider