inventree / InvenTree

Open Source Inventory Management System
https://docs.inventree.org
MIT License
4.32k stars 781 forks source link

API endpoint plugins_metadata_retrieve fails with ERR 500 #7825

Closed flborn closed 3 months ago

flborn commented 3 months ago

Please verify that this bug has NOT been raised before.

Describe the bug*

I'm in the middle of building a GUI for the Inventree / KiCad integration via plugin 'kicad-library-plugin'. I'm new to the Inventree Development Ecosystem, but as far as I can see, the plugin options for each enabled category are stored in the metadata. Since it can be tedious to enable 50+ categories to be available in KiCad, I tried to access the data via the API endpoint 'plugins_metadata_retrieve'.

However this always fails with an Error 500 and the additional message { "error": "AssertionError", "error_class": "<class 'AssertionError'>", "detail": "Error details can be found in the admin panel", "path": "/api/plugins/digikeyplugin/metadata/", "status_code": 500 }

The admin panals says the following: `Traceback (most recent call last):

File "/root/.local/lib/python3.11/site-packages/rest_framework/views.py", line 506, in dispatch response = handler(request, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/root/.local/lib/python3.11/site-packages/rest_framework/generics.py", line 252, in get return self.retrieve(request, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/root/.local/lib/python3.11/site-packages/rest_framework/mixins.py", line 54, in retrieve instance = self.get_object() ^^^^^^^^^^^^^^^^^

File "/root/.local/lib/python3.11/site-packages/rest_framework/generics.py", line 88, in get_object assert lookup_url_kwarg in self.kwargs, ( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

AssertionError: Expected view MetadataView to be called with a URL keyword argument named "key". Fix your URL conf, or set the .lookup_field attribute on the view correctly.`

This happens with the mentioned plugin 'kicad-library-plugin' as well as with default plugins like 'inventreelabelmachine'.

Steps to Reproduce

  1. Make an HTTP request to 'http://inventree.local/api/plugins/digikeyplugin/metadata/', using BasicAuth and GET method.

Expected behaviour

Response code 200. If there is no metadata for the plugin, return an empty json {}

Deployment Method

Version Information

Version Information:

InvenTree-Version: 0.16.0 dev Django Version: 4.2.14 Commit Hash: 6937b3a Commit Date: 2024-08-05

Database: postgresql Debug-Mode: False Deployed using Docker: True Platform: Linux-6.5.0-27-generic-x86_64-with Installer: DOC

Active plugins: [{'name': 'InvenTreeBarcode', 'slug': 'inventreebarcode', 'version': '2.1.0'}, {'name': 'InvenTreeCoreNotificationsPlugin', 'slug': 'inventreecorenotificationsplugin', 'version': '1.0.0'}, {'name': 'InvenTreeCurrencyExchange', 'slug': 'inventreecurrencyexchange', 'version': '1.0.0'}, {'name': 'InvenTreeLabel', 'slug': 'inventreelabel', 'version': '1.1.0'}, {'name': 'InvenTreeLabelMachine', 'slug': 'inventreelabelmachine', 'version': '1.0.0'}, {'name': 'InvenTreeLabelSheet', 'slug': 'inventreelabelsheet', 'version': '1.0.0'}, {'name': 'DigiKeyPlugin', 'slug': 'digikeyplugin', 'version': '1.0.0'}, {'name': 'LCSCPlugin', 'slug': 'lcscplugin', 'version': '1.0.0'}, {'name': 'MouserPlugin', 'slug': 'mouserplugin', 'version': '1.0.0'}, {'name': 'TMEPlugin', 'slug': 'tmeplugin', 'version': '1.0.0'}, {'name': 'KiCadLibraryPlugin', 'slug': 'kicad-library-plugin', 'version': '1.4.2'}]

Please verify if you can reproduce this bug on the demo site.

Relevant log output

Traceback (most recent call last):

File "/root/.local/lib/python3.11/site-packages/rest_framework/views.py", line 506, in dispatch
response = handler(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/root/.local/lib/python3.11/site-packages/rest_framework/generics.py", line 252, in get
return self.retrieve(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/root/.local/lib/python3.11/site-packages/rest_framework/mixins.py", line 54, in retrieve
instance = self.get_object()
^^^^^^^^^^^^^^^^^

File "/root/.local/lib/python3.11/site-packages/rest_framework/generics.py", line 88, in get_object
assert lookup_url_kwarg in self.kwargs, (
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

AssertionError: Expected view MetadataView to be called with a URL keyword argument named "key". Fix your URL conf, or set the `.lookup_field` attribute on the view correctly.
matmair commented 3 months ago

Can reproduce

SchrodingersGat commented 3 months ago

@flborn thanks for reporting - fix incoming in https://github.com/inventree/InvenTree/pull/7829