netbox-community / pynetbox

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

Fix updating custom filed of type JSON #472

Closed Kani999 closed 1 year ago

Kani999 commented 2 years ago

Close #457

Since there is no existing PR, I've created one which is based on @markkuleinio solution

FliesLikeABrick commented 2 years ago

+1 I installed pynetbox from this branch and it resolved my inability to update JSON custom properties with the error cited in #457

FliesLikeABrick commented 2 years ago

@zachmoody can you review this? It would be great to have this fix come in upstream to fix our automation and let us avoid having to create an internal fork

abhi1693 commented 2 years ago

@Kani999 This change does not seem to be the right way to handle this scenario. IMO, you should update the flatten_custom to something like

def flatten_custom(custom_dict):
    return {
        k: v if not isinstance(v, dict) else v["id"] for k, v in custom_dict.items()
    }

custom_dict always contains the id field which I believe used to be referred to as value in the older versions.

Kani999 commented 2 years ago

@abhi1693 I've changed the flatten_custom method, which basically does nothing at the moment. So it works like a previous change.

custom_dict always contains the id field which I believe used to be referred to as value in the older versions.

That's not true. Item contains just a key and value, there is no id or anything else. Example of custom_dict parameter:

type(custom_dict) <class 'dict'>

{'TEST': 'blah blah blah', 
 'json_data': {'a': 1, 
               'b': 2}}
rodvand commented 2 years ago

Any news on merging this? The issue this PR addresses also affects the ansible modules.