pynetbox icon indicating copy to clipboard operation
pynetbox copied to clipboard

Fix updating custom filed of type JSON

Open Kani999 opened this issue 2 years ago • 5 comments

Close #457

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

Kani999 avatar Jun 14 '22 07:06 Kani999

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

FliesLikeABrick avatar Jun 14 '22 21:06 FliesLikeABrick

@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

FliesLikeABrick avatar Jun 20 '22 15:06 FliesLikeABrick

@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.

abhi1693 avatar Jun 22 '22 17:06 abhi1693

@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}}

Kani999 avatar Jun 27 '22 09:06 Kani999

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

rodvand avatar Sep 18 '22 17:09 rodvand