-
Notifications
You must be signed in to change notification settings - Fork 33
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
Calling getattr(pynautobot_object, attribute, default_value) with a default argument resets changes #197
Comments
This seems like "working as intended" as the simple addition of |
For the project I'm currently working on, I'm making Lots™ of changes of various types to our Nautobot data. As an optimization, I make changes to all objects of a particular class and them perform a parallelized
Note that 64 objects is something of a small operation; in this case, it was all the interfaces on two devices. Updating all the interfaces on 20 or 30 devices at once is easily possible for us. Additionally, it feels counterintuitive to me that an ostensibly read-only action (reading an attribute), can result in a write operation as a silent side-effect. Mumble mumble Principle of Least Surprise and so forth. =) |
Would switching to a Bulk Update operation (pynautobot 2.1.0+) benefit you? You could build a list of dictionaries of the objects you want to update and pass that into the |
Oh, I realize that you are still on Nautobot 1.6 😞 |
Nautobot 1.6 (and therefore pynautobot 1.X) is in LTM status so we definitely won't be making any large changes to the code base for those older versions - only bug and security fixes. |
Yep, I absolutely get the LTM status here; this "silently updating my object out from under me if I read an object's attributes in a certain way" felt like a bug to me is all. Obviously I can (and have) worked around it, but I didn't want anyone else to get bitten by it if possible. |
Environment
Nautobot: 1.6.21
pynautobot: 1.5.2
Details
If you:
iface
)iface.description = "foo"
) but do not callsave()
getattr(iface, "bad_attribute", "default_value")
)…then the updates are lost because:
Note: there are other paths to trigger this same issue; using either the two-argument form of
getattr()
or even just referencing the attribute directly viafoo = my_pynautobot_object.bad_attribute
will have the same effect provided one wraps the call in a try/except block:The text was updated successfully, but these errors were encountered: