NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.48k stars 13.66k forks source link

paperless-ngx: PIL import error when editing documents #190850

Closed Moredread closed 2 years ago

Moredread commented 2 years ago

Describe the bug

I'm using paperless 1.8.0 from unstable on a nixos-22.05 system. (via the services.paperless.package option) The paperless 1.6.0 in 22.05. does work without issue.

When editing a document in the web interface the preview is missing. The Firefox Web Developer Tools shows a 500 error for requests to /metadata URLs.

In the server log Django shows import error for PIL:

[2022-09-11 21:35:28,536] [ERROR] [django.request] Internal Server Error: /api/documents/2/metadata/
Traceback (most recent call last):
  File "/nix/store/wr8fklzw183j22khr0w7kmyqy5b7jxa7-python3.10-asgiref-3.5.2/lib/python3.10/site-packages/asgiref/sync.py", line 472, in thread_handler
    raise exc_info[1]
  File "/nix/store/63hrd5abwgir584jkzwp597xqv2qnj5g-python3.10-Django-4.1.1/lib/python3.10/site-packages/django/core/handlers/exception.py", line 42, in inner
    response = await get_response(request)
  File "/nix/store/63hrd5abwgir584jkzwp597xqv2qnj5g-python3.10-Django-4.1.1/lib/python3.10/site-packages/django/core/handlers/base.py", line 253, in _get_response_async
    response = await wrapped_callback(
  File "/nix/store/wr8fklzw183j22khr0w7kmyqy5b7jxa7-python3.10-asgiref-3.5.2/lib/python3.10/site-packages/asgiref/sync.py", line 435, in __call__
    ret = await asyncio.wait_for(future, timeout=None)
  File "/nix/store/rdm31z7s8m6aaydnq949g2zql4wixsgd-python3-3.9.13/lib/python3.9/asyncio/tasks.py", line 442, in wait_for
    return await fut
  File "/nix/store/wr8fklzw183j22khr0w7kmyqy5b7jxa7-python3.10-asgiref-3.5.2/lib/python3.10/site-packages/asgiref/current_thread_executor.py", line 22, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/nix/store/wr8fklzw183j22khr0w7kmyqy5b7jxa7-python3.10-asgiref-3.5.2/lib/python3.10/site-packages/asgiref/sync.py", line 476, in thread_handler
    return func(*args, **kwargs)
  File "/nix/store/63hrd5abwgir584jkzwp597xqv2qnj5g-python3.10-Django-4.1.1/lib/python3.10/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/nix/store/bn79ll0ya8h8h4hylizirmm1w4fq5xzb-python3.10-djangorestframework-3.13.1/lib/python3.10/site-packages/rest_framework/viewsets.py", line 125, in view
    return self.dispatch(request, *args, **kwargs)
  File "/nix/store/bn79ll0ya8h8h4hylizirmm1w4fq5xzb-python3.10-djangorestframework-3.13.1/lib/python3.10/site-packages/rest_framework/views.py", line 509, in dispatch
    response = self.handle_exception(exc)
  File "/nix/store/bn79ll0ya8h8h4hylizirmm1w4fq5xzb-python3.10-djangorestframework-3.13.1/lib/python3.10/site-packages/rest_framework/views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/nix/store/bn79ll0ya8h8h4hylizirmm1w4fq5xzb-python3.10-djangorestframework-3.13.1/lib/python3.10/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
    raise exc
  File "/nix/store/bn79ll0ya8h8h4hylizirmm1w4fq5xzb-python3.10-djangorestframework-3.13.1/lib/python3.10/site-packages/rest_framework/views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
  File "/nix/store/r0jh15b4fj8vq49aajxn35009w7v8gav-paperless-ngx-1.8.0/lib/paperless-ngx/src/documents/views.py", line 313, in metadata
    "original_metadata": self.get_metadata(doc.source_path, doc.mime_type),
  File "/nix/store/r0jh15b4fj8vq49aajxn35009w7v8gav-paperless-ngx-1.8.0/lib/paperless-ngx/src/documents/views.py", line 284, in get_metadata
    parser = parser_class(progress_callback=None, logging_group=None)
  File "/nix/store/r0jh15b4fj8vq49aajxn35009w7v8gav-paperless-ngx-1.8.0/lib/paperless-ngx/src/paperless_tesseract/signals.py", line 2, in get_parser
    from .parsers import RasterisedDocumentParser
  File "/nix/store/r0jh15b4fj8vq49aajxn35009w7v8gav-paperless-ngx-1.8.0/lib/paperless-ngx/src/paperless_tesseract/parsers.py", line 9, in <module>
    from PIL import Image
  File "/nix/store/p04s8rxk8r0vjwb9k73dmdakr00xzg35-python3.10-pillow-9.2.0/lib/python3.10/site-packages/PIL/Image.py", line 100, in <module>
    from . import _imaging as core
ImportError: cannot import name '_imaging' from 'PIL' (/nix/store/p04s8rxk8r0vjwb9k73dmdakr00xzg35-python3.10-pillow-9.2.0/lib/python3.10/site-packages/PIL/__init__.py)

Steps To Reproduce

Steps to reproduce the behavior:

  1. Enable the paperless service, configure a superuser and login in the Web UI
  2. At the top right click the username and go to settings. Make sure that 'Use PDF viewer provided by the browser' is enabled. Save.
  3. Add a document (e.g. a PDF) in the Web UI
  4. Edit the document, notice missing preview on the right side
  5. See logs for error message, e.g. via journalctl

Expected behavior

See the PDF document while editing.

Notify maintainers

@Flakebi @erikarvstedt @lukegb @gador

Metadata

 - system: `"x86_64-linux"`
 - host os: `Linux 5.15.64, NixOS, 22.05 (Quokka), 22.05.2992.45b56b5321a`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.8.1`
 - channels(root): `"home-manager-22.05.tar.gz, lorri, mozilla-overlay, nixos-22.05, nixos-hardware, nixos-unstable, nixpkgs-22.05, nixpks-21.11, nur"`
 - channels(addy): `"home-manager-22.05.tar.gz, lorri, mozilla-overlay, nixos-22.05, nixos-hardware, nixos-unstable, nixpkgs-22.05, nur"`
 - nixpkgs: `/home/addy/.nix-defexpr/channels/nixpkgs`
Moredread commented 2 years ago

It looks like it's an issue specific to using the unstable package on the stable release. My guess is that the service config invokes the webserver with stable gunicorn (with gunicorn) but with the unstable paperless package environment, which doesn't mix well (esp. when they both use different Python versions).

See https://github.com/NixOS/nixpkgs/blob/3a0710d12a9cf4dc07812b54f8d9f3a344445ee5/nixos/modules/services/misc/paperless.nix#L285 and https://github.com/NixOS/nixpkgs/blob/3a0710d12a9cf4dc07812b54f8d9f3a344445ee5/nixos/modules/services/misc/paperless.nix#L300

erikarvstedt commented 2 years ago

Does #190888 fix this?