inventree / inventree-python

Python library for communication with inventree via API
https://docs.inventree.org/en/latest/api/python/python/
MIT License
26 stars 34 forks source link

Cannot add remote_image link when creating part. #162

Closed diminDDL closed 1 year ago

diminDDL commented 1 year ago

When attempting to create a part with the following data:

args = {
    'name': template,
    'description': fields['description'],
    'category': category.pk,
    'default_location': location.pk,
    'component': True,
    'is_template': True,
    'remote_image': "https://media.rs-online.com/t_medium/Y1448515-01.jpg"
     }
templateObj = Part.create(api, args)

I get the following exception:

Traceback (most recent call last):
  File "/home/dmytro/Documents/projects/quickinventory/quicklcsc.py", line 237, in main
    templateObj = Part.create(api, args)
  File "/home/dmytro/.local/lib/python3.10/site-packages/inventree/base.py", line 144, in create
    response = api.post(cls.URL, data)
  File "/home/dmytro/.local/lib/python3.10/site-packages/inventree/api.py", line 375, in post
    response = self.request(
  File "/home/dmytro/.local/lib/python3.10/site-packages/inventree/api.py", line 327, in request
    raise requests.exceptions.HTTPError(detail)
requests.exceptions.HTTPError: {'detail': 'Error occurred during API request', 'url': 'http://192.168.1.100:1337/api/part/', 'method': 'POST', 'status_code': 500, 'body': '{"error":"TypeError","error_class":"<class \'TypeError\'>","detail":"Error details can be found in the admin panel","path":"/api/part/","status_code":500}', 'headers': {'AUTHORIZATION': 'Token ce3485c697ac90b26892ccd05c6b25ac13540e90'}, 'params': {'format': 'json'}, 'data': {'name': '47uF 1210 16V', 'description': '16V 47uF X5R ±10% 1210 Multilayer Ceramic Capacitors MLCC - SMD/SMT ROHS', 'category': 4, 'default_location': 2, 'component': True, 'is_template': True, 'remote_image': 'https://media.rs-online.com/t_medium/Y1448515-01.jpg'}}

In the admin panel:

Part() got an unexpected keyword argument 'remote_image'

Traceback (most recent call last):

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

File "/root/.local/lib/python3.9/site-packages/rest_framework/generics.py", line 242, in post return self.create(request, *args, **kwargs)

File "/usr/local/lib/python3.9/contextlib.py", line 79, in inner return func(*args, **kwds)

File "/home/inventree/InvenTree/part/api.py", line 1074, in create serializer.is_valid(raise_exception=True)

File "/root/.local/lib/python3.9/site-packages/rest_framework/serializers.py", line 227, in is_valid self._validated_data = self.run_validation(self.initial_data)

File "/home/inventree/InvenTree/InvenTree/serializers.py", line 177, in run_validation instance = self.Meta.model(**data)

File "/root/.local/lib/python3.9/site-packages/mptt/models.py", line 410, in init super(MPTTModel, self).init(*args, **kwargs)

File "/root/.local/lib/python3.9/site-packages/django/db/models/base.py", line 503, in init raise TypeError("%s() got an unexpected keyword argument '%s'" % (cls.name, kwarg))

TypeError: Part() got an unexpected keyword argument 'remote_image'

SchrodingersGat commented 1 year ago

@diminDDL thanks for reporting this. I can confirm the bug - it will be fixed in https://github.com/inventree/InvenTree/pull/4264 :)