Skip to content

Commit d511f44

Browse files
TPT 1880: Fixed issue with updating non-populated NodeBalancerNode (#277)
## 📝 Description Previously, attempting to update a non-populated NodeBalancerNode would result in the update actually updating the resource silently. This change fixes the issue. ## ✔️ How to Test `pytest test` Note: Since this change deals with making updates to real resources as opposed to fixtures, it cannot be tested using mocks and must therefore be tested manually. To do this, first create a NodeBalancerNode in your Linode account if one does not already exist, and then run this python script and verify that the weight of the node was actually updated. ``` #!/usr/bin/env python3 from linode_api4 import LinodeClient from linode_api4.objects import NodeBalancerNode client = LinodeClient(<personal_access_token>) node = NodeBalancerNode(client, <node_id>, <config_id>, <nodebalancer_id>) node.weight = 60 node.save() ``` Resolves #97
1 parent 233a899 commit d511f44

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

linode_api4/objects/base.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,26 @@ def save(self, force=True) -> bool:
210210
if not force and not self._changed:
211211
return False
212212

213-
resp = self._client.put(
214-
type(self).api_endpoint, model=self, data=self._serialize()
215-
)
213+
data = None
214+
if not self._populated:
215+
data = {
216+
a: object.__getattribute__(self, a)
217+
for a in type(self).properties
218+
if type(self).properties[a].mutable
219+
and object.__getattribute__(self, a) is not None
220+
}
221+
222+
for key, value in data.items():
223+
if (
224+
isinstance(value, ExplicitNullValue)
225+
or value == ExplicitNullValue
226+
):
227+
data[key] = None
228+
229+
else:
230+
data = self._serialize()
231+
232+
resp = self._client.put(type(self).api_endpoint, model=self, data=data)
216233

217234
if "error" in resp:
218235
return False

0 commit comments

Comments
 (0)