Skip to content

Commit 072b670

Browse files
committed
Keep null values when stipping unmodified data
1 parent 311dbf3 commit 072b670

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

infrahub_sdk/node/node.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -234,15 +234,10 @@ def _generate_input_data( # noqa: C901
234234

235235
rel: RelatedNodeBase | RelationshipManagerBase = getattr(self, item_name)
236236

237-
# BLOCKED by https://github.com/opsmill/infrahub/issues/330
238-
# if (
239-
# item is None
240-
# and item_name in self._relationships
241-
# and self._schema.get_relationship(item_name).cardinality == "one"
242-
# ):
243-
# data[item_name] = None
244-
# continue
245-
# el
237+
if rel_schema.cardinality == RelationshipCardinality.ONE and rel_schema.optional and not rel.initialized:
238+
data[item_name] = None
239+
continue
240+
246241
if rel is None or not rel.initialized:
247242
continue
248243

@@ -315,7 +310,8 @@ def _strip_unmodified_dict(data: dict, original_data: dict, variables: dict, ite
315310
variables.pop(variable_key)
316311

317312
# TODO: I do not feel _great_ about this
318-
if not data_item and data_item != [] and item in data:
313+
# -> I don't even know who you are -- gmazoyer (quoting Thanos)
314+
if data_item in ({}, []) or (data_item is None and original_data.get(item) is None):
319315
data.pop(item)
320316

321317
def _strip_unmodified(self, data: dict, variables: dict) -> tuple[dict, dict]:
@@ -324,7 +320,9 @@ def _strip_unmodified(self, data: dict, variables: dict) -> tuple[dict, dict]:
324320
relationship_property = getattr(self, relationship)
325321
if not relationship_property or relationship not in data:
326322
continue
327-
if not relationship_property.initialized:
323+
if not relationship_property.initialized and (
324+
not isinstance(relationship_property, RelatedNodeBase) or not relationship_property.schema.optional
325+
):
328326
data.pop(relationship)
329327
elif isinstance(relationship_property, RelationshipManagerBase) and not relationship_property.has_update:
330328
data.pop(relationship)

0 commit comments

Comments
 (0)