Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't reset object attribute to its initial value. #586

Open
endreszabo opened this issue Sep 19, 2023 · 0 comments
Open

Can't reset object attribute to its initial value. #586

endreszabo opened this issue Sep 19, 2023 · 0 comments
Labels
type: bug A confirmed report of unexpected behavior in the application

Comments

@endreszabo
Copy link

endreszabo commented Sep 19, 2023

pynetbox version

v7.0.1

NetBox version

v3.6.1

Python version

3.11

Steps to Reproduce

Consider this simple modifying of a given attribute:

>>> import pynetbox
>>> nb=pynetbox.api('http://127.0.0.1:8000', 'yada')
>>> br_native = nb.dcim.interfaces.get(id=411)
>>> eth3 = nb.dcim.interfaces.get(id=415)
>>> eth3.bridge
br-native
>>> eth3.bridge = None
>>> eth3.save()
True
>>> eth3.bridge = br_native
>>> eth3.save()
False

#and, for added confusion, changing to another bridge works again.
>>> br_users = nb.dcim.interfaces.get(id=412)
>>> eth3.bridge = br_users
>>> eth3.save()
True

Expected Behavior

This happens because _diff() in response.py returns False as the desired state matches its initial internal state, coming from the _init_cache list.

We've been here many times. Yes, I know I should have called .full_details() after the .save() to have the attributes fetched and populated again. Yes, I know pynetbox is not an ORM and it just abstracts API calls, but let's be honest, this whole way of working is highly misleading, especially for newbies.

Observed Behavior

I propose to:

  • mention this behavior in the documentation,
  • or add Api an option that makes pynetbox reload the object once it was saved or updated, like this: nb=pynetbox.api('http://127.0.0.1:8000', 'yada', always_reload=True)
  • or rename/alias this full_details() to reload() or something else that makes more sense
  • or have the Record update its own _init_cache. I know this is hard/impossible without getting back the object from NetBox and doing so would incur performance penalties; hence, I don't recommend it to be enabled by default.
@endreszabo endreszabo added the type: bug A confirmed report of unexpected behavior in the application label Sep 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

No branches or pull requests

1 participant