inventree / inventree-brother-plugin

Label printing plugin for Brother series printers
MIT License
16 stars 12 forks source link

Installing plugin crashes server #12

Closed murray484 closed 1 year ago

murray484 commented 1 year ago

Hi, I'm trying to install this plugin on a fresh instance of Inventree. When I add the plugin 'inventree-brother-plugin' to my plugins.txt file, the server fails to start and I see this log in my 'inventree-worker' container:

/home/inventree/data/config.yaml exists - skipping
InvenTree translation coverage: 19%
Waiting for database...
Database connection sucessful!
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
Traceback (most recent call last):
  File "/home/inventree/InvenTree/plugin/registry.py", line 273, in collect_plugins
    plugin._get_package_metadata()
  File "/home/inventree/InvenTree/plugin/plugin.py", line 297, in _get_package_metadata
    meta = metadata(cls.__name__)
  File "/usr/local/lib/python3.9/importlib/metadata.py", line 559, in metadata
    return Distribution.from_name(distribution_name).metadata
  File "/usr/local/lib/python3.9/importlib/metadata.py", line 196, in from_name
    raise PackageNotFoundError(name)
importlib.metadata.PackageNotFoundError: BrotherLabelPlugin

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/inventree/InvenTree/plugin/helpers.py", line 68, in handle_error
    package_name = pathlib.Path(package_path).relative_to(install_path).parts[0]
  File "/usr/local/lib/python3.9/pathlib.py", line 939, in relative_to
    raise ValueError("{!r} is not in the subpath of {!r}"
ValueError: '/usr/local/lib/python3.9/importlib/metadata.py' is not in the subpath of '/usr/local/lib/python3.9/site-packages' OR one path is relative and the other is absolute.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/inventree/InvenTree/manage.py", line 23, in <module>
    execute_from_command_line(sys.argv)
  File "/root/.local/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/root/.local/lib/python3.9/site-packages/django/core/management/__init__.py", line 395, in execute
    django.setup()
  File "/root/.local/lib/python3.9/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/root/.local/lib/python3.9/site-packages/django/apps/registry.py", line 122, in populate
    app_config.ready()
  File "/home/inventree/InvenTree/plugin/apps.py", line 46, in ready
    registry.collect_plugins()
  File "/home/inventree/InvenTree/plugin/registry.py", line 276, in collect_plugins
    handle_error(error, do_raise=False, log_name='discovery')
  File "/home/inventree/InvenTree/plugin/helpers.py", line 71, in handle_error
    path_obj = pathlib.Path(package_path).relative_to(settings.BASE_DIR)
  File "/usr/local/lib/python3.9/pathlib.py", line 939, in relative_to
    raise ValueError("{!r} is not in the subpath of {!r}"
ValueError: '/usr/local/lib/python3.9/importlib/metadata.py' is not in the subpath of '/home/inventree/InvenTree' OR one path is relative and the other is absolute.
/home/inventree/data/config.yaml exists - skipping
InvenTree translation coverage: 19%
Waiting for database...
Database connection sucessful!

Any ideas on how to resolve this?

matmair commented 1 year ago

@murray484 with the given information no. What version of InvenTree are you running, what plugin verison, on what OS and with what deployment method?

murray484 commented 1 year ago

@matmair I'm running Inventree v0.8.3, plugin version is the latest on pip, running using docker-compose (with the production docker-compose file from the install tutorial) on Ubuntu 22.04.

SchrodingersGat commented 1 year ago
ValueError: '/usr/local/lib/python3.9/importlib/metadata.py' is not in the subpath of '/usr/local/lib/python3.9/site-packages' OR one path is relative and the other is absolute.

@matmair looks like an issue relating to python venv pathing perhaps?

matmair commented 1 year ago

@SchrodingersGat could be a bug we fixed in 0.8.x release regarding error detection and path traversal. Depends on the executing environment though.

SchrodingersGat commented 1 year ago

I can reproduce this pretty simply, by adding inventree-brother-plugin to plugins.txt

It looks like the importlib metadata (added recently) errors out, most likely due to pathing if the plugins are installed within the venv context?

matmair commented 1 year ago

I will have a look after work.

It looks like the importlib metadata (added recently) errors out, most likely due to pathing if the plugins are installed within the venv context?

Could be 🤷

matmair commented 1 year ago

Ok on dev I can reproduce, but not in production. The solution I thought of is not working, might have to dig deeper.

SchrodingersGat commented 1 year ago

@murray484 I have raised an issue in the InvenTree code base, I believe that this is a fundemental error not linked just to this plugin:

https://github.com/inventree/InvenTree/issues/3767