janeczku / calibre-web

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

Internal Server Error when accessing `/admin/user` URLs #1823

Closed duckpuppy closed 3 years ago

duckpuppy commented 3 years ago

Describe the bug/problem When running calibre-web 0.6.10 via the linuxserver docker image, I get a 500 error when accessing any /admin/user URLs. Other users on the same image (which means a different DB) do not have this issue which leads me to believe that it may be related to data in the DB. Reverting to the 0.6.9 linuxserver image works with no error. In the log snippet below, I think the unknown locale 'ale' error may be the culprit, but I don't know where that locale is coming from.

To Reproduce Steps to reproduce the behavior:

  1. Go to admin
  2. Click on any user or new user button
  3. See error

Logfile

[2021-01-19 16:29:05,233] ERROR {cps:1891} Exception on /admin/user/1 [GET]
Traceback (most recent call last):
  File "/app/calibre-web/cps/db.py", line 713, in speaking_language
    cur_l = LC.parse(lang.lang_code)
  File "/usr/local/lib/python3.8/dist-packages/babel/core.py", line 331, in parse
    raise UnknownLocaleError(input_id)
babel.core.UnknownLocaleError: unknown locale 'ale'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.8/dist-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/usr/local/lib/python3.8/dist-packages/flask_login/utils.py", line 272, in decorated_view
    return func(*args, **kwargs)
  File "/app/calibre-web/cps/admin.py", line 90, in inner
    return f(*args, **kwargs)
  File "/app/calibre-web/cps/admin.py", line 1176, in edit_user
    languages = calibre_db.speaking_language()
  File "/app/calibre-web/cps/db.py", line 716, in speaking_language
    lang.name = _(isoLanguages.get(part3=lang.lang_code).name)
  File "/usr/local/lib/python3.8/dist-packages/iso639/iso639.py", line 265, in get
    return getattr(self, key)[value]
  File "/usr/local/lib/python3.8/dist-packages/iso639/iso639.py", line 105, in __get__
    val = self.f(instance)
  File "/usr/local/lib/python3.8/dist-packages/iso639/iso639.py", line 186, in part3
    return dict((x.part3, x) for x in self.languages if x.part3)
  File "/usr/local/lib/python3.8/dist-packages/iso639/iso639.py", line 105, in __get__
    val = self.f(instance)
  File "/usr/local/lib/python3.8/dist-packages/iso639/iso639.py", line 174, in languages
    l, i, m, p5, p2, p1 = _fabtabular()
  File "/usr/local/lib/python3.8/dist-packages/iso639/iso639.py", line 20, in _fabtabular
    from pkg_resources import resource_filename
ModuleNotFoundError: No module named 'pkg_resources'

Expected behavior User edit or creation screen comes up

Environment (please complete the following information):

Additional context Moving back to the 0.6.9 linuxserver image works

duckpuppy commented 3 years ago

I found the issue... one of the books in my library had the language set incorrectly to "Aleut" somehow, and that was causing the crash. It's strange that it did not cause that on 0.6.9, but if anyone legitimately has books in the Aleut language, that may be an issue for them. Since the error was in code populating the "Language of Books" dropdown, I reverted to 0.6.9 and looked at the dropdown. "Aleut" looked like a reasonable cause for the code looking for a locale called ale.

CHBMB commented 3 years ago

Mystery solved!

CHBMB commented 3 years ago

@duckpuppy once I knew how to reproduce it, it gave me something to work with. Adding python3-pkg-resources I think has fixed the issue, up until now it's been a build time dependency only.

Thanks for the investigating. Hands down the most interesting issue I can recall and now I know about the Aleut people of USA/Russia which was a super interesting Wikipedia read. Do you speak the language? I was amazed by the low number of Aleut people in the world.

duckpuppy commented 3 years ago

Awesome! No, I don't know how to speak Aleutian, but now I want to find some samples and see what it's like.

On Wed, Jan 20, 2021 at 4:36 AM chbmb notifications@github.com wrote:

@duckpuppy https://github.com/duckpuppy once I knew how to reproduce it, it gave me something to work with. Adding python3-pkg-resources I think has fixed the issue, up until now it's been a build time dependency only.

Thanks for the investigating. Hands down the most interesting issue I can recall and now I know about the Aleut people of USA/Russia which was a super interesting Wikipedia https://en.m.wikipedia.org/wiki/Aleut read. Do you speak the language? I was amazed by the low number of Aleut people in the world.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/janeczku/calibre-web/issues/1823#issuecomment-763471414, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAEWNNCYHOFOH6CYH4Q6OLS22P2LANCNFSM4WJRNLGA .

-- SELECT * FROM users WHERE clue > 0

OzzieIsaacs commented 3 years ago

@duckpuppy: I can't reproduce the problem with the Aleut language, which UI language do you use?

CHBMB commented 3 years ago

@OzzieIsaacs Don't worry, I think this is fixed and was a runtime dependency in the container. Installing python3-pkg-resources fixed it as far as I can tell by testing and I've pushed the fix my end.

duckpuppy commented 3 years ago

You probably wouldn't see the problem in a development scenario, since the development requirements would install the resources package as a dependency - I just don't think they're installed by the runtime dependencies in requirements.txt. I have English set as the UI language.

On Thu, Jan 21, 2021 at 4:17 PM chbmb notifications@github.com wrote:

@OzzieIsaacs https://github.com/OzzieIsaacs Don't worry, I think this is fixed and was a runtime dependency in the container. Installing python3-pkg-resources fixed it as far as I can tell by testing and I've pushed the fix my end.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/janeczku/calibre-web/issues/1823#issuecomment-764947029, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAEWNP64TWJX4GNMDRXWX3S3CKVHANCNFSM4WJRNLGA .

-- SELECT * FROM users WHERE clue > 0

OzzieIsaacs commented 3 years ago

I‘ll close the issue then