Skip to content

Commit ded0452

Browse files
Add ExplicitNullValue support
1 parent 06f8a5f commit ded0452

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

linode_api4/objects/linode_interfaces.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from dataclasses import dataclass, field
2-
from typing import List, Optional
2+
from typing import List, Optional, Union
33

4-
from linode_api4.objects.base import Base, Property
4+
from linode_api4.objects.base import Base, ExplicitNullValue, Property
55
from linode_api4.objects.dbase import DerivedBase
66
from linode_api4.objects.networking import Firewall
77
from linode_api4.objects.serializable import JSONObject
@@ -193,13 +193,10 @@ class LinodeInterfaceOptions(JSONObject):
193193
NOTE: Linode interfaces may not currently be available to all users.
194194
"""
195195

196-
always_include = {
197-
# If a default firewall_id isn't configured, the API requires that
198-
# firewall_id is defined in the LinodeInterface POST body.
199-
"firewall_id"
200-
}
196+
# If a default firewall_id isn't configured, the API requires that
197+
# firewall_id is defined in the LinodeInterface POST body.
198+
firewall_id: Union[int, ExplicitNullValue, None] = None
201199

202-
firewall_id: Optional[int] = None
203200
default_route: Optional[LinodeInterfaceDefaultRouteOptions] = None
204201
vpc: Optional[LinodeInterfaceVPCOptions] = None
205202
public: Optional[LinodeInterfacePublicOptions] = None

linode_api4/objects/serializable.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,16 @@ def attempt_serialize(value: Any) -> Any:
186186
if issubclass(type(value), JSONObject):
187187
return value._serialize(is_put=is_put)
188188

189+
# Needed to avoid circular imports without a breaking change
190+
from linode_api4.objects.base import ( # pylint: disable=import-outside-toplevel
191+
ExplicitNullValue,
192+
)
193+
194+
if value == ExplicitNullValue or isinstance(
195+
value, ExplicitNullValue
196+
):
197+
return None
198+
189199
return value
190200

191201
def should_include(key: str, value: Any) -> bool:

test/integration/conftest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from requests.exceptions import ConnectionError, RequestException
1414

1515
from linode_api4 import (
16+
ExplicitNullValue,
1617
InterfaceGeneration,
1718
LinodeInterfaceDefaultRouteOptions,
1819
LinodeInterfaceOptions,
@@ -585,6 +586,7 @@ def linode_with_linode_interfaces(
585586
public=LinodeInterfacePublicOptions(),
586587
),
587588
LinodeInterfaceOptions(
589+
firewall_id=ExplicitNullValue,
588590
vpc=LinodeInterfaceVPCOptions(
589591
subnet_id=subnet.id,
590592
),

0 commit comments

Comments
 (0)