From 75c812df46d675884d6e3b4498f041633b7a8f49 Mon Sep 17 00:00:00 2001 From: ezilber-akamai Date: Fri, 28 Apr 2023 11:42:27 -0400 Subject: [PATCH 1/4] Fixed issue with updating non-populated NodeBalancerNode --- linode_api4/objects/base.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/linode_api4/objects/base.py b/linode_api4/objects/base.py index 26859087..8c796efb 100644 --- a/linode_api4/objects/base.py +++ b/linode_api4/objects/base.py @@ -210,9 +210,23 @@ def save(self, force=True) -> bool: if not force and not self._changed: return False - resp = self._client.put( - type(self).api_endpoint, model=self, data=self._serialize() - ) + if not self._populated: + result = { + a: getattr(self, a) + for a in type(self).properties + if type(self).properties[a].mutable + and object.__getattribute__(self, a) is not None + and hasattr(self, a) + } + # pdb.set_trace() + + resp = self._client.put( + type(self).api_endpoint, model=self, data=result + ) + else: + resp = self._client.put( + type(self).api_endpoint, model=self, data=self._serialize() + ) if "error" in resp: return False From 2e173ff66de2f0f950cd38f5d4ebc34ea5eca87d Mon Sep 17 00:00:00 2001 From: ezilber-akamai Date: Fri, 28 Apr 2023 12:03:37 -0400 Subject: [PATCH 2/4] Fixed issue causing failing test --- linode_api4/objects/base.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/linode_api4/objects/base.py b/linode_api4/objects/base.py index 8c796efb..2a535378 100644 --- a/linode_api4/objects/base.py +++ b/linode_api4/objects/base.py @@ -218,7 +218,10 @@ def save(self, force=True) -> bool: and object.__getattribute__(self, a) is not None and hasattr(self, a) } - # pdb.set_trace() + + for key, value in result.items(): + if isinstance(value, ExplicitNullValue) or value == ExplicitNullValue: + result[key] = None resp = self._client.put( type(self).api_endpoint, model=self, data=result From e23c6a13a153fc7d46f7be4722db69af7b128ea1 Mon Sep 17 00:00:00 2001 From: ezilber-akamai Date: Fri, 28 Apr 2023 12:04:55 -0400 Subject: [PATCH 3/4] Lint --- linode_api4/objects/base.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/linode_api4/objects/base.py b/linode_api4/objects/base.py index 2a535378..1f4e163a 100644 --- a/linode_api4/objects/base.py +++ b/linode_api4/objects/base.py @@ -220,7 +220,10 @@ def save(self, force=True) -> bool: } for key, value in result.items(): - if isinstance(value, ExplicitNullValue) or value == ExplicitNullValue: + if ( + isinstance(value, ExplicitNullValue) + or value == ExplicitNullValue + ): result[key] = None resp = self._client.put( From c7e28e753f578da14612319b36bbfdb5c0984109 Mon Sep 17 00:00:00 2001 From: ezilber-akamai Date: Wed, 3 May 2023 13:16:39 -0400 Subject: [PATCH 4/4] Addressed PR comments --- linode_api4/objects/base.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/linode_api4/objects/base.py b/linode_api4/objects/base.py index 1f4e163a..be72a395 100644 --- a/linode_api4/objects/base.py +++ b/linode_api4/objects/base.py @@ -210,29 +210,26 @@ def save(self, force=True) -> bool: if not force and not self._changed: return False + data = None if not self._populated: - result = { - a: getattr(self, a) + data = { + a: object.__getattribute__(self, a) for a in type(self).properties if type(self).properties[a].mutable and object.__getattribute__(self, a) is not None - and hasattr(self, a) } - for key, value in result.items(): + for key, value in data.items(): if ( isinstance(value, ExplicitNullValue) or value == ExplicitNullValue ): - result[key] = None + data[key] = None - resp = self._client.put( - type(self).api_endpoint, model=self, data=result - ) else: - resp = self._client.put( - type(self).api_endpoint, model=self, data=self._serialize() - ) + data = self._serialize() + + resp = self._client.put(type(self).api_endpoint, model=self, data=data) if "error" in resp: return False