netbox-community / pynetbox

Python API client library for Netbox.
Apache License 2.0
567 stars 168 forks source link

Endpoint update() Not Working #515

Closed wz4 closed 1 year ago

wz4 commented 1 year ago

Endpoint update is not working. Type must be converted to a str on line 358.

if not isinstance(objects, list): raise ValueError( "Objects passed must be list[dict|Record] - was " + type(objects) )

wz4 commented 1 year ago

Correction - problem is occurring on update() exception. I was not sending payload as a list.

claremont-awilson commented 1 year ago

I'm seeing the same issue, not sure if it's my syntax? Works fine with create, just not update:

nb.virtualization.virtual_machines.update(dict(name="vm_test",cluster={"name": "cluster_test"},vcpus=float(2),memory=2048))

Error:

Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.6/site-packages/pynetbox/core/endpoint.py", line 364, in update "Objects passed must be list[dict|Record] - was " + type(objects) TypeError: must be str, not type

markkuleinio commented 1 year ago

@claremont-awilson The endpoint-level .update() method requires a list of objects that should be updated, and you didn't provide a list but a dict.

How about this:

nb.virtualization.virtual_machines.update([dict(name="vm_test",cluster={"name": "cluster_test"},vcpus=float(2),memory=2048)])

@wz4 Feel free to close this issue as well.

claremont-awilson commented 1 year ago

Thank you!

Got a different error with that:

Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.6/site-packages/pynetbox/core/endpoint.py", line 374, in update raise ValueError("id is missing from object: " + str(o)) ValueError: id is missing from object: {'name': 'vm_test', 'cluster': {'name': 'cluster_test'}, 'vcpus': 2.0, 'memory': 2048}

But that error was easier for me to understand, and made me realise I also need to include the 'id' when doing an update:

nb.virtualization.virtual_machines.update([dict(id=505,name="vm_test",cluster={"name": "cluster_test"},
vcpus=float(2),memory=2048)])

Output:

[vm_test]

Thank you again.