question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Updating object with JSON custom field causes a traceback

See original GitHub issue

I have a JSON custom field on some objects in my NetBox 3.2beta instance. When trying to update one of the objects I get this traceback.

Traceback (most recent call last):
  File "/home/jcollie/dev/netbox-maintenance/fix-model-aliases.py", line 602, in <module>
    main()
  File "/usr/lib/python3.10/site-packages/click/core.py", line 1137, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3.10/site-packages/click/core.py", line 1062, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3.10/site-packages/click/core.py", line 763, in invoke
    return __callback(*args, **kwargs)
  File "/home/jcollie/dev/netbox-maintenance/fix-model-aliases.py", line 597, in main
    if device_type.save():
  File "/home/jcollie/.local/lib/python3.10/site-packages/pynetbox/core/response.py", line 529, in save
    updates = self.updates()
  File "/home/jcollie/.local/lib/python3.10/site-packages/pynetbox/core/response.py", line 506, in updates
    diff = self._diff()
  File "/home/jcollie/.local/lib/python3.10/site-packages/pynetbox/core/response.py", line 484, in _diff
    {fmt_dict(k, v) for k, v in self.serialize(init=True).items()}
  File "/home/jcollie/.local/lib/python3.10/site-packages/pynetbox/core/response.py", line 457, in serialize
    ret[i] = flatten_custom(current_val)
  File "/home/jcollie/.local/lib/python3.10/site-packages/pynetbox/core/response.py", line 61, in flatten_custom
    return {
  File "/home/jcollie/.local/lib/python3.10/site-packages/pynetbox/core/response.py", line 62, in <dictcomp>
    k: v if not isinstance(v, dict) else v["value"] for k, v in custom_dict.items()
KeyError: 'value'

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:8
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
mrlockecommented, Jun 13, 2022

Thanks @rodvand. I’ve tested the solution proposed above by markkuleinio and now everything works. Not sure if it may break something else, but up to the moment all other automations I’ve works fine.

It will be really nice if this can be included in pynetbox production release.

2reactions
Kani999commented, Nov 16, 2022

Any workaround for this that you know of? I am stuck at updating our objects now when we use custom_fields as objects.

– Kind Regards Falk

I’ve forked the repository and did a small change https://github.com/Kani999/pynetbox/tree/fix_cf_6.6.2

Then I released the forked version to pypi, so I can simply install it in my projects.

I’m trying to maintain the version with the original pynetbox, but I don’t guarantee anything in the future

Read more comments on GitHub >

github_iconTop Results From Across the Web

redmine - updating a list type custom field failed - Stack Overflow
I'm trying to update a list type custom field, with json like {'id': xx, "name": "xxxx", ... Traceback (most recent call last): File ......
Read more >
Advanced field editing using JSON | Cloud automation Cloud
The JSON object can contain the attributes update or fields, for example: ... "My Text Customfield": "this is the same field as above...
Read more >
Scripting Samples - Atlassian JIRA Plugins | Quisapps
root cause: Traceback (most recent call last): File ... Here is a Post Function I am using to update a custom field with...
Read more >
jsonmerge - PyPI
As you can see, when encountering an JSON object, jsonmerge by default returns fields that appear in either base or head document. For...
Read more >
traceback — Print or retrieve a stack traceback — Python 3.11 ...
Print up to limit stack trace entries from traceback object tb (starting from ... In particular, the __context__ field is calculated only if...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found