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

SKU: "Not a valid string" #134

Closed eeintech closed 2 years ago

eeintech commented 2 years ago

There is apparently a "string checker" that was added to check part numbers and it rejects hyphens/dashes. This is not acceptable as A LOT of part numbers and SKUs use this symbol.

Here's the SKU tested: 1292-1630-1-ND

And the traceback:

Traceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/francois/Desktop/kicad/Ki-nTree/kintree_gui.py", line 4, in <module>
    kintree_gui.main()
  File "/home/francois/Desktop/kicad/Ki-nTree/kintree/kintree_gui.py", line 1166, in main
    new_part, part_pk, part_data = inventree_interface.inventree_create(part_info=part_info,
  File "/home/francois/Desktop/kicad/Ki-nTree/kintree/database/inventree_interface.py", line 543, in inventree_create
    is_supplier_part_created = inventree_api.create_supplier_part(part_id=part_pk,
  File "/home/francois/Desktop/kicad/Ki-nTree/kintree/database/inventree_api.py", line 464, in create_supplier_part
    supplier_part = SupplierPart.create(inventree_api, {
  File "/home/francois/Desktop/kicad/Ki-nTree/.venv/lib/python3.8/site-packages/inventree/base.py", line 144, in create
    response = api.post(cls.URL, data)
  File "/home/francois/Desktop/kicad/Ki-nTree/.venv/lib/python3.8/site-packages/inventree/api.py", line 375, in post
    response = self.request(
  File "/home/francois/Desktop/kicad/Ki-nTree/.venv/lib/python3.8/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://127.0.0.1:8000/api/company/part/', 'method': 'POST', 'status_code': 400, 'body': '{"SKU":["Not a valid string."]}', 'headers': {'AUTHORIZATION': 'Token b2a3a1a69698d6086cb61ab21ff481db81b566b4'}, 'params': {'format': 'json'}, 'data': {'part': 446, 'manufacturer': 'Walsin Technology Corporation', 'MPN': '0402B104K160CT', 'supplier': 1, 'SKU': ['1292-1630-1-ND'], 'link': 'https://www.digikey.com/en/products/detail/walsin-technology-corporation/0402B104K160CT/6707534', 'description': 'CAP CER 0.1UF 16V X7R 0402'}}

EDIT: This is related to the API, this is not a limitation in InvenTree.

eeintech commented 2 years ago

By lack of time to investigate, I didn't notice the brackets around the string, duh! My own fault, everything is fine on the API side :smile: