@@ -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,16 @@ 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 (but this is not great indeed) -- gmazoyer (quoting Thanos)
314+ original_data_item = original_data .get (item )
315+ original_data_item_is_none = original_data_item is None
316+ if isinstance (original_data_item , dict ):
317+ if "node" in original_data_item :
318+ original_data_item_is_none = original_data_item ["node" ] is None
319+ elif "id" not in original_data_item :
320+ original_data_item_is_none = True
321+
322+ if item in data and (data_item in ({}, []) or (data_item is None and original_data_item_is_none )):
319323 data .pop (item )
320324
321325 def _strip_unmodified (self , data : dict , variables : dict ) -> tuple [dict , dict ]:
@@ -324,7 +328,9 @@ def _strip_unmodified(self, data: dict, variables: dict) -> tuple[dict, dict]:
324328 relationship_property = getattr (self , relationship )
325329 if not relationship_property or relationship not in data :
326330 continue
327- if not relationship_property .initialized :
331+ if not relationship_property .initialized and (
332+ not isinstance (relationship_property , RelatedNodeBase ) or not relationship_property .schema .optional
333+ ):
328334 data .pop (relationship )
329335 elif isinstance (relationship_property , RelationshipManagerBase ) and not relationship_property .has_update :
330336 data .pop (relationship )
0 commit comments