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

Create Part endpoint returns a list holding one part instead just the part #231

Closed second-string closed 3 weeks ago

second-string commented 1 month ago

I upgraded my inventree installation from 0.14.X to 0.15.3, and now the python client breaks when parsing a response for creating a part. Here's the stack trace:

Traceback (most recent call last):
  File "/Users/user/Developer/app/app.py", line 711, in <module>
    part_to_edit = inventree_create_new_part(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user/Developer/app/app.py", line 565, in inventree_create_new_part
    new_part = Part.create(inventree_api, new_part_data)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user/Developer/app/.venv/lib/python3.11/site-packages/inventree/base.py", line 172, in create
    return cls(api, data=response)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user/Developer/app/.venv/lib/python3.11/site-packages/inventree/base.py", line 47, in __init__
    pk = data.get('pk', None)
         ^^^^^^^^
AttributeError: 'list' object has no attribute 'get'

It's because the response from the POST to /part is returning a list of one element, the part. The only version of this package that's on pip is 0.13.5, and I saw you just pushed 0.14 a few weeks ago. As far as I can see in the code here, that still doesn't fix this issue. Looking at the blame in inventree repo, it seems like this 'list vs. dict' behaviour has been like this for a while now, but the inventree docs still show just a single Part returned for creation. Am I missing something silly here?

The exception is thrown in the InvenTreeObject base class initialiser, so the only workaround I can think of right now is to add a custom initializer to the Part class that specifically calls the init funcs of all the supers? My python ability gets pretty hazy once I start getting to this multiple inheritance and mixin stuff, not sure how I handle all of them as super classes/mixins.

I haven't checked any of the other endpoints from the python client yet, this is blocking my application from doing anything else.

EDIT: Added this gross hack to the Part class:


    def __init__(self, api, data):
        super().__init__(api, data=data[0])

That works for the creation of the part, but my next API calls fail creating PartParameters with the same error, "'list' object has no attribute 'get'".

SchrodingersGat commented 1 month ago

@second-string strange. You will need to provide the actual data that the API is returning when you submit the erroneous "list" request.

second-string commented 1 month ago

Here's the log of the python Response object before it's parsed out of json (you can see the single ' on both ends of the payload wrapping it). The data = json.loads(response.text) line parses it into a list with a single object.

(Pdb) p response.text
'[{"active":true,"assembly":false,"barcode_hash":"","category":6,"component":true,"creation_date":"2024-05-26","creation_user":2,"default_expiry":0,"default_location":null,"default_supplier":null,"description":"CAP CER 0.1UF 50V X7R 0603","full_name":"CL10B104KB8NNNC_Samsung-Electro-Mechanics | CL10B104KB8NNNC","image":"/media/part_images/part_18_image.png","IPN":"CL10B104KB8NNNC_Samsung-Electro-Mechanics","is_template":false,"keywords":null,"last_stocktake":null,"link":"https://www.digikey.com/en/products/detail/samsung-electro-mechanics/CL10B104KB8NNNC/3886658","minimum_stock":0.0,"name":"CL10B104KB8NNNC","notes":null,"pk":18,"purchaseable":true,"revision":null,"salable":false,"starred":false,"thumbnail":"/media/part_images/part_18_image.thumbnail.png","trackable":false,"units":"","variant_of":null,"virtual":false,"pricing_min":null,"pricing_max":null,"pricing_updated":"2024-05-26 16:16","responsible":null,"allocated_to_build_orders":0.0,"allocated_to_sales_orders":0.0,"building":0.0,"category_default_location":null,"in_stock":100.0,"ordering":0.0,"required_for_build_orders":0,"required_for_sales_orders":0,"stock_item_count":1,"suppliers":0,"total_in_stock":100.0,"external_stock":0.0,"unallocated_stock":100.0,"variant_stock":0.0,"copy_category_parameters":true,"tags":[]},{"active":true,"assembly":false,"barcode_hash":"","category":6,"component":true,"creation_date":"2024-05-26","creation_user":2,"default_expiry":0,"default_location":null,"default_supplier":null,"description":"CAP CER 1UF 25V X7R 0603","full_name":"CL10B105KA8NNNC_Samsung-Electro-Mechanics | CL10B105KA8NNNC","image":"/media/part_images/part_17_image.png","IPN":"CL10B105KA8NNNC_Samsung-Electro-Mechanics","is_template":false,"keywords":null,"last_stocktake":null,"link":"https://www.digikey.com/en/products/detail/samsung-electro-mechanics/CL10B105KA8NNNC/3886842","minimum_stock":0.0,"name":"CL10B105KA8NNNC","notes":null,"pk":17,"purchaseable":true,"revision":null,"salable":false,"starred":false,"thumbnail":"/media/part_images/part_17_image.thumbnail.png","trackable":false,"units":"","variant_of":null,"virtual":false,"pricing_min":null,"pricing_max":null,"pricing_updated":"2024-05-26 16:11","responsible":null,"allocated_to_build_orders":0.0,"allocated_to_sales_orders":0.0,"building":0.0,"category_default_location":null,"in_stock":3.0,"ordering":0.0,"required_for_build_orders":0,"required_for_sales_orders":0,"stock_item_count":1,"suppliers":0,"total_in_stock":3.0,"external_stock":0.0,"unallocated_stock":3.0,"variant_stock":0.0,"copy_category_parameters":true,"tags":[]},{"active":true,"assembly":false,"barcode_hash":"","category":69,"component":true,"creation_date":"2024-05-26","creation_user":2,"default_expiry":0,"default_location":null,"default_supplier":null,"description":"MOSFET BVDSS: 8V~24V SOT23 T&R 3","full_name":"DMP2065U-7_Diodes-Incorporated | DMP2065U-7","image":"/media/part_images/part_24_image.png","IPN":"DMP2065U-7_Diodes-Incorporated","is_template":false,"keywords":null,"last_stocktake":null,"link":"https://www.digikey.com/en/products/detail/diodes-incorporated/DMP2065U-7/16547882","minimum_stock":0.0,"name":"DMP2065U-7","notes":null,"pk":24,"purchaseable":true,"revision":null,"salable":false,"starred":false,"thumbnail":"/media/part_images/part_24_image.thumbnail.png","trackable":false,"units":"","variant_of":null,"virtual":false,"pricing_min":null,"pricing_max":null,"pricing_updated":"2024-05-26 16:41","responsible":null,"allocated_to_build_orders":0.0,"allocated_to_sales_orders":0.0,"building":0.0,"category_default_location":null,"in_stock":2.0,"ordering":0.0,"required_for_build_orders":0,"required_for_sales_orders":0,"stock_item_count":1,"suppliers":0,"total_in_stock":2.0,"external_stock":0.0,"unallocated_stock":2.0,"variant_stock":0.0,"copy_category_parameters":true,"tags":[]},{"active":true,"assembly":false,"barcode_hash":"","category":63,"component":true,"creation_date":"2024-05-26","creation_user":2,"default_expiry":0,"default_location":null,"default_supplier":null,"description":"RES SMD 470 OHM 5% 2/3W 1206","full_name":"ERJ-P08J471V_Panasonic-Electronic-Components | ERJ-P08J471V","image":"/media/part_images/part_27_image.png","IPN":"ERJ-P08J471V_Panasonic-Electronic-Components","is_template":false,"keywords":null,"last_stocktake":null,"link":"https://www.digikey.com/en/products/detail/panasonic-electronic-components/ERJ-P08J471V/525396","minimum_stock":0.0,"name":"ERJ-P08J471V","notes":null,"pk":27,"purchaseable":true,"revision":null,"salable":false,"starred":false,"thumbnail":"/media/part_images/part_27_image.thumbnail.png","trackable":false,"units":"","variant_of":null,"virtual":false,"pricing_min":null,"pricing_max":null,"pricing_updated":"2024-05-26 16:54","responsible":null,"allocated_to_build_orders":0.0,"allocated_to_sales_orders":0.0,"building":0.0,"category_default_location":null,"in_stock":7.0,"ordering":0.0,"required_for_build_orders":0,"required_for_sales_orders":0,"stock_item_count":1,"suppliers":0,"total_in_stock":7.0,"external_stock":0.0,"unallocated_stock":7.0,"variant_stock":0.0,"copy_category_parameters":true,"tags":[]},{"active":true,"assembly":false,"barcode_hash":"","category":29,"component":true,"creation_date":"2024-05-26","creation_user":2,"default_expiry":0,"default_location":null,"default_supplier":null,"description":"RECTIFIER, SCHOTTKY, 2A, 40V, ES","full_name":"FS24_Good-Ark-Semiconductor | FS24","image":"/media/part_images/part_25_image.png","IPN":"FS24_Good-Ark-Semiconductor","is_template":false,"keywords":null,"last_stocktake":null,"link":"https://www.digikey.com/en/products/detail/good-ark-semiconductor/FS24/18667767","minimum_stock":0.0,"name":"FS24","notes":null,"pk":25,"purchaseable":true,"revision":null,"salable":false,"starred":false,"thumbnail":"/media/part_images/part_25_image.thumbnail.png","trackable":false,"units":"","variant_of":null,"virtual":false,"pricing_min":null,"pricing_max":null,"pricing_updated":"2024-05-26 16:43","responsible":null,"allocated_to_build_orders":0.0,"allocated_to_sales_orders":0.0,"building":0.0,"category_default_location":null,"in_stock":3.0,"ordering":0.0,"required_for_build_orders":0,"required_for_sales_orders":0,"stock_item_count":1,"suppliers":0,"total_in_stock":3.0,"external_stock":0.0,"unallocated_stock":3.0,"variant_stock":0.0,"copy_category_parameters":true,"tags":[]},{"active":true,"assembly":false,"barcode_hash":"","category":6,"component":true,"creation_date":"2024-05-26","creation_user":2,"default_expiry":0,"default_location":null,"default_supplier":null,"description":"CAP CER 0.1UF 50V X7R 0603","full_name":"KGM15BR71H104KT_KYOCERA-AVX | KGM15BR71H104KT","image":"/media/part_images/part_19_image.png","IPN":"KGM15BR71H104KT_KYOCERA-AVX","is_template":false,"keywords":null,"last_stocktake":null,"link":"https://www.digikey.com/en/products/detail/kyocera-avx/KGM15BR71H104KT/1600046","minimum_stock":0.0,"name":"KGM15BR71H104KT","notes":null,"pk":19,"purchaseable":true,"revision":null,"salable":false,"starred":false,"thumbnail":"/media/part_images/part_19_image.thumbnail.png","trackable":false,"units":"","variant_of":null,"virtual":false,"pricing_min":null,"pricing_max":null,"pricing_updated":"2024-05-26 16:20","responsible":null,"allocated_to_build_orders":0.0,"allocated_to_sales_orders":0.0,"building":0.0,"category_default_location":null,"in_stock":10.0,"ordering":0.0,"required_for_build_orders":0,"required_for_sales_orders":0,"stock_item_count":1,"suppliers":0,"total_in_stock":10.0,"external_stock":0.0,"unallocated_stock":10.0,"variant_stock":0.0,"copy_category_parameters":true,"tags":[]},{"active":true,"assembly":false,"barcode_hash":"","category":36,"component":true,"creation_date":"2024-05-26","creation_user":2,"default_expiry":0,"default_location":null,"default_supplier":null,"description":"IC TRANSCEIVER FULL 2/2 24SQFN","full_name":"LAN8720A-CP-ABC_Microchip-Technology | LAN8720A-CP-ABC","image":"/media/part_images/part_26_image.png","IPN":"LAN8720A-CP-ABC_Microchip-Technology","is_template":false,"keywords":null,"last_stocktake":null,"link":"https://www.digikey.com/en/products/detail/microchip-technology/LAN8720A-CP-ABC/6192901","minimum_stock":0.0,"name":"LAN8720A-CP-ABC","notes":null,"pk":26,"purchaseable":true,"revision":null,"salable":false,"starred":false,"thumbnail":"/media/part_images/part_26_image.thumbnail.png","trackable":false,"units":"","variant_of":null,"virtual":false,"pricing_min":null,"pricing_max":null,"pricing_updated":"2024-05-26 16:50","responsible":null,"allocated_to_build_orders":0.0,"allocated_to_sales_orders":0.0,"building":0.0,"category_default_location":null,"in_stock":1.0,"ordering":0.0,"required_for_build_orders":0,"required_for_sales_orders":0,"stock_item_count":1,"suppliers":0,"total_in_stock":1.0,"external_stock":0.0,"unallocated_stock":1.0,"variant_stock":0.0,"copy_category_parameters":true,"tags":[]},{"active":true,"assembly":false,"barcode_hash":"","category":28,"component":true,"creation_date":"2024-05-26","creation_user":2,"default_expiry":0,"default_location":null,"default_supplier":null,"description":"LED GREEN CLEAR CHIP SMD BOT ENT","full_name":"LTST-C230KGKT_Lite-On-Inc. | LTST-C230KGKT","image":"/media/part_images/part_30_image.png","IPN":"LTST-C230KGKT_Lite-On-Inc.","is_template":false,"keywords":null,"last_stocktake":null,"link":"https://www.digikey.com/en/products/detail/liteon/LTST-C230KGKT/386855","minimum_stock":0.0,"name":"LTST-C230KGKT","notes":null,"pk":30,"purchaseable":true,"revision":null,"salable":false,"starred":false,"thumbnail":"/media/part_images/part_30_image.thumbnail.png","trackable":false,"units":"","variant_of":null,"virtual":false,"pricing_min":null,"pricing_max":null,"pricing_updated":"2024-05-26 16:58","responsible":null,"allocated_to_build_orders":0.0,"allocated_to_sales_orders":0.0,"building":0.0,"category_default_location":null,"in_stock":3.0,"ordering":0.0,"required_for_build_orders":0,"required_for_sales_orders":0,"stock_item_count":1,"suppliers":0,"total_in_stock":3.0,"external_stock":0.0,"unallocated_stock":3.0,"variant_stock":0.0,"copy_category_parameters":true,"tags":[]},{"active":true,"assembly":false,"barcode_hash":"","category":63,"component":true,"creation_date":"2024-05-26","creation_user":2,"default_expiry":0,"default_location":null,"default_supplier":null,"description":"RES 6.8K OHM 5% 1/10W 0603","full_name":"RC0603JR-076K8L_YAGEO | RC0603JR-076K8L","image":"/media/part_images/part_29_image.png","IPN":"RC0603JR-076K8L_YAGEO","is_template":false,"keywords":null,"last_stocktake":null,"link":"https://www.digikey.com/en/products/detail/yageo/RC0603JR-076K8L/726813","minimum_stock":0.0,"name":"RC0603JR-076K8L","notes":null,"pk":29,"purchaseable":true,"revision":null,"salable":false,"starred":false,"thumbnail":"/media/part_images/part_29_image.thumbnail.png","trackable":false,"units":"","variant_of":null,"virtual":false,"pricing_min":null,"pricing_max":null,"pricing_updated":"2024-05-26 16:56","responsible":null,"allocated_to_build_orders":0.0,"allocated_to_sales_orders":0.0,"building":0.0,"category_default_location":null,"in_stock":8.0,"ordering":0.0,"required_for_build_orders":0,"required_for_sales_orders":0,"stock_item_count":1,"suppliers":0,"total_in_stock":8.0,"external_stock":0.0,"unallocated_stock":8.0,"variant_stock":0.0,"copy_category_parameters":true,"tags":[]},{"active":true,"assembly":false,"barcode_hash":"","category":63,"component":true,"creation_date":"2024-05-26","creation_user":2,"default_expiry":0,"default_location":null,"default_supplier":null,"description":"RES 47K OHM 1% 1/10W 0603","full_name":"RMCF0603FT47K0_Stackpole-Electronics-Inc | RMCF0603FT47K0","image":"/media/part_images/part_12_image.png","IPN":"RMCF0603FT47K0_Stackpole-Electronics-Inc","is_template":false,"keywords":null,"last_stocktake":null,"link":"https://www.digikey.com/en/products/detail/stackpole-electronics-inc/RMCF0603FT47K0/1761148","minimum_stock":0.0,"name":"RMCF0603FT47K0","notes":null,"pk":12,"purchaseable":true,"revision":null,"salable":false,"starred":false,"thumbnail":"/media/part_images/part_12_image.thumbnail.png","trackable":false,"units":"","variant_of":null,"virtual":false,"pricing_min":null,"pricing_max":null,"pricing_updated":"2024-05-26 16:01","responsible":null,"allocated_to_build_orders":0.0,"allocated_to_sales_orders":0.0,"building":0.0,"category_default_location":null,"in_stock":9.0,"ordering":0.0,"required_for_build_orders":0,"required_for_sales_orders":0,"stock_item_count":1,"suppliers":0,"total_in_stock":9.0,"external_stock":0.0,"unallocated_stock":9.0,"variant_stock":0.0,"copy_category_parameters":true,"tags":[]},{"active":true,"assembly":false,"barcode_hash":"","category":63,"component":true,"creation_date":"2024-05-26","creation_user":2,"default_expiry":0,"default_location":null,"default_supplier":null,"description":"RES 5.1 OHM 1% 1/10W 0603","full_name":"RMCF0603FT5R10_Stackpole-Electronics-Inc | RMCF0603FT5R10","image":"/media/part_images/part_28_image.png","IPN":"RMCF0603FT5R10_Stackpole-Electronics-Inc","is_template":false,"keywords":null,"last_stocktake":null,"link":"https://www.digikey.com/en/products/detail/stackpole-electronics-inc/RMCF0603FT5R10/1761181","minimum_stock":0.0,"name":"RMCF0603FT5R10","notes":null,"pk":28,"purchaseable":true,"revision":null,"salable":false,"starred":false,"thumbnail":"/media/part_images/part_28_image.thumbnail.png","trackable":false,"units":"","variant_of":null,"virtual":false,"pricing_min":null,"pricing_max":null,"pricing_updated":"2024-05-26 16:56","responsible":null,"allocated_to_build_orders":0.0,"allocated_to_sales_orders":0.0,"building":0.0,"category_default_location":null,"in_stock":10.0,"ordering":0.0,"required_for_build_orders":0,"required_for_sales_orders":0,"stock_item_count":1,"suppliers":0,"total_in_stock":10.0,"external_stock":0.0,"unallocated_stock":10.0,"variant_stock":0.0,"copy_category_parameters":true,"tags":[]},{"active":true,"assembly":false,"barcode_hash":"","category":63,"component":true,"creation_date":"2024-05-26","creation_user":2,"default_expiry":0,"default_location":null,"default_supplier":null,"description":"RES 0 OHM JUMPER 1/10W 0603","full_name":"RMCF0603ZT0R00_Stackpole-Electronics-Inc | RMCF0603ZT0R00","image":"/media/part_images/part_14_image.png","IPN":"RMCF0603ZT0R00_Stackpole-Electronics-Inc","is_template":false,"keywords":null,"last_stocktake":null,"link":"https://www.digikey.com/en/products/detail/stackpole-electronics-inc/RMCF0603ZT0R00/1756908","minimum_stock":0.0,"name":"RMCF0603ZT0R00","notes":null,"pk":14,"purchaseable":true,"revision":null,"salable":false,"starred":false,"thumbnail":"/media/part_images/part_14_image.thumbnail.png","trackable":false,"units":"","variant_of":null,"virtual":false,"pricing_min":null,"pricing_max":null,"pricing_updated":"2024-05-26 16:03","responsible":null,"allocated_to_build_orders":0.0,"allocated_to_sales_orders":0.0,"building":0.0,"category_default_location":null,"in_stock":100.0,"ordering":0.0,"required_for_build_orders":0,"required_for_sales_orders":0,"stock_item_count":1,"suppliers":0,"total_in_stock":100.0,"external_stock":0.0,"unallocated_stock":100.0,"variant_stock":0.0,"copy_category_parameters":true,"tags":[]}]'

I can dump this into a gist or a file to make it easier to read if you want.

EDIT: as i look through it a bit it's not just a list of the single created object, it's a list of every part that's in my InvenTree database... All of this is getting retuned just by calling Part.create in the python api.

SchrodingersGat commented 1 month ago

I am not able to reproduce this issue. On the latest code I can create a simple part without issue. Also we test this as part of CI.

Are you sure that the POST request is made against /part ? it should be /part/ with a trailing slash I think.

second-string commented 1 month ago

When you say 'latest code', is that building from source from the head of master for this repo, or the latest version available on pypi, 0.13.5? I will dig into this more this week

second-string commented 1 month ago

Also, what instance of InvenTree is your api communicating with?

SchrodingersGat commented 1 month ago

This is with the latest (master branch) of InvenTree, and the 0.14.0 python bindings

second-string commented 1 month ago

I'm out of town at the moment but will upgrade the python client and give it another try when I'm back. Thanks for the info

second-string commented 3 weeks ago
> /Users/me/Developer/project/.venv/lib/python3.12/site-packages/inventree/api.py(359)request()
-> response = methods[method](api_url, **payload)
(Pdb) p api_url
'http://<my remote inventree url>/api/part/'
(Pdb) 

Here is the printout of payload:

{"params": {"format": "json"}, "timeout": 10, "headers": {"AUTHORIZATION": "Token inv-7e2d18f06729c4ddff5b6f63ad9df6f058958dad-20240530"}, "auth": None, "proxies": {}, "json": {"name": "LTST-C230KRKT", "IPN": "LTST-C230KRKT_Lite-On-Inc.", "description": "LED RED CLR CHIP SMD BOTTOM ENT", "category": 28, "active": True, "virtual": False, "assembly": False, "component": True, "remote_image": "https://mm.digikey.com/Volume0/opasdata/d220001/medias/images/912/LTST-C230KAKT%2CLTST-C230KGKT%2CLTST-C230KRKT%2CLTST-C230KSKT.jpg", "is_template": False, "link": "https://www.digikey.com/en/products/detail/liteon/LTST-C230KRKT/386857", "purchaseable": True, "salable": False, "starred": False}}

This is the exact same whether on 0.13.5 or 0.14.0. It seems like it's not an issue with the python client, since it works for you, but rather what my inventree install is returning.

This is the output of inventree run invoke version on my remote machine that's running InvenTree:

[526] root@name-of-machine ../~ $ inventree run invoke version                                                                                                                                                                                                                                                                                                                                                                        

Node is available but yarn is not. Install yarn if you wish to build the frontend.                                                                                                                                                                                                                                                                                                                                                        

InvenTree - inventree.org                                                                                                                                                                                                                                                                                                                                                                                                                 
The Open-Source Inventory Management System                                                                                                                                                                                                                                                                                                                                                                                               

Installation paths:                                                                                                                                                                                                                                                                                                                                                                                                                       
Base        /opt/inventree                                                                                                                                                                                                                                                                                                                                                                                                                
Config      /etc/inventree/config.yaml                                                                                                                                                                                                                                                                                                                                                                                                    
Media       /opt/inventree/data/media                                                                                                                                                                                                                                                                                                                                                                                                     
Static      /opt/inventree/data/static                                                                                                                                                                                                                                                                                                                                                                                                    

Versions:                                                                                                                                                                                                                                                                                                                                                                                                                                 
Python      3.9.5                                                                                                                                                                                                                                                                                                                                                                                                                         
Django      4.2.12                                                                                                                                                                                                                                                                                                                                                                                                                        
InvenTree   0.15.3                                                                                                                                                                                                                                                                                                                                                                                                                        
API         196                                                                                                                                                                                                                                                                                                                                                                                                                           
Node        v20.14.0                                                                                                                                                                                                                                                                                                                                                                                                                      
Yarn        N/A                                                                                                                                                                                                                                                                                                                                                                                                                           

Commit hash:None                                                                                                                                                                                                                                                                                                                                                                                                                          
Commit date:None

I've verified that it's actually POSTin in the debugger, but the response code is a 200. According to the docs it should be 201, which would make canonical sense for a POST creation. Instead it's a 200 with a full list of all of the parts already in my parts list. ~Is it possible to enable debug logging of the running inventree instance (or to tail the backend logs somewhere) to see if something is erroring in the logic which is falling back to returning all parts?~ I've tried to look through the inventree backend codebase but I'm much more versed in node API code, I don't know the right place to look for this codebase.

I've set INVENTREE_LOG_LEVEL to DEBUG and INVENTREE_DB_LOGGING to True in the config file, and running journalctl -u <service> -f allows me to tail the running logs.

I tried to look at the requests being made by the frontend when a part is created manually, but it's not helpful. There's a request made to api/part/category/tree/ to list the categories for the new part, and one to /api/part/parameter/?search=&part=32 I'm assuming to try to find associated parameters, but no post show in the the browser dev tools to any part creation link. Then it just loads all the js and css for the new page, finally with a GET to /part/32/ to load the actual part.

One interesting thing is that I don't have any DB service running that I can see? systemctl status | grep -i invent gives me this:

[546] root@machine-name ../InvenTree $ systemctl status | grep -i invent                                                                                                                                                                                                                                                                                                                                                               
           │   │ └─251296 grep invent                                                                                                                                                                                                                                                                                                                                                                                                     
             ├─inventree-worker.service                                                                                                                                                                                                                                                                                                                                                                                                   
             ├─inventree.service                                                                                                                                                                                                                                                                                                                                                                                                          
             ├─inventree-worker-1.service                                                                                                                                                                                                                                                                                                                                                                                                 
             ├─inventree-web-1.service                                                                                                                                                                                                                                                                                                                                                                                                    
             │ ├─250845 /opt/inventree/env/bin/python3.9 env/bin/gunicorn --chdir /opt/inventree/src/backend/InvenTree -c src/backend/InvenTree/gunicorn.conf.py InvenTree.wsgi -b 0.0.0.0:6000                                                                                                                                                                                                                                           
             │ ├─250963 /opt/inventree/env/bin/python3.9 env/bin/gunicorn --chdir /opt/inventree/src/backend/InvenTree -c src/backend/InvenTree/gunicorn.conf.py InvenTree.wsgi -b 0.0.0.0:6000                                                                                                                                                                                                                                           
             │ ├─250964 /opt/inventree/env/bin/python3.9 env/bin/gunicorn --chdir /opt/inventree/src/backend/InvenTree -c src/backend/InvenTree/gunicorn.conf.py InvenTree.wsgi -b 0.0.0.0:6000                                                                                                                                                                                                                                           
             │ ├─250965 /opt/inventree/env/bin/python3.9 env/bin/gunicorn --chdir /opt/inventree/src/backend/InvenTree -c src/backend/InvenTree/gunicorn.conf.py InvenTree.wsgi -b 0.0.0.0:6000                                                                                                                                                                                                                                           
             │ ├─250966 /opt/inventree/env/bin/python3.9 env/bin/gunicorn --chdir /opt/inventree/src/backend/InvenTree -c src/backend/InvenTree/gunicorn.conf.py InvenTree.wsgi -b 0.0.0.0:6000                                                                                                                                                                                                                                           
             │ └─250967 /opt/inventree/env/bin/python3.9 env/bin/gunicorn --chdir /opt/inventree/src/backend/InvenTree -c src/backend/InvenTree/gunicorn.conf.py InvenTree.wsgi -b 0.0.0.0:6000                                                                                                                                                                                                                                           
             ├─inventree-web.service

Should there be something managing the database? I haven't changed any of the defaults around the db stuff I don't think.

second-string commented 3 weeks ago

Oh wow this was a fun one. I was finally able to figure it out between the debug log of of the inventree-web-1 service and setting the python module's logger output level to debug.

Basically, when creating a part with the web interface, everything in the web service logs. There was the main POST call for creation, along with a few others like the category and everything that I mentioned already. When I used the python api, even though I breakpointed right at the requests call that was firing and confirmed URL and payload, this was the log output of inventree-web-1:

DEBUG:inventree:Sending Request:
DEBUG:inventree: - URL: POST http://<remote url>/api/part/
DEBUG:inventree: - params: {format: json}
DEBUG:inventree: - timeout: 10
DEBUG:inventree: - headers: {AUTHORIZATION: Token inv-<token>}
DEBUG:inventree: - auth: None
DEBUG:inventree: - proxies: {}
DEBUG:inventree: - json: {<standard part json>}
DEBUG:urllib3.connectionpool:Starting new HTTP connection (1): <remote url>:80
DEBUG:urllib3.connectionpool:http://<remote url>:80 "POST /api/part/?format=json HTTP/1.1" 301 178
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): <remote url>:443
DEBUG:urllib3.connectionpool:https://<remote url>:443 "GET /api/part/?format=json HTTP/1.1" 200 16210
INFO:inventree:Request: POST http://<remote url>/api/part/ - 200

You can see that it first tries http w/ port 80, because that's the URL I had set in the python code. My nginx setup redirects 80 to 443 for SSL, which the python requests module properly handles. But in following that redirect, it falls back to GET, instead of maintaining the proper POST call. That's why I was just getting a list of my parts, because the call that actually got through to the server looked just like a regular 'get all parts' query.

So the fix for me was just make my URL in my python code https to avoid the redirect.

I'm not entirely sure why the requests module internally switches the method? Everything I can find seems to show that it shouldn't. Maybe it's something to do with the odd way that each requests.<method> is stored in the module code? Or maybe it's just a bug in requests. Regardless, problem is fixed. Thanks for the help.