Skip to content

Commit 49335ca

Browse files
authored
Merge pull request #517 from opsmill/stable
2 parents ab99599 + fe666d0 commit 49335ca

File tree

9 files changed

+2408
-1065
lines changed

9 files changed

+2408
-1065
lines changed

changelog/479.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Allow unsetting optional relationship of cardinality one by setting its value to `None`

changelog/519.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Bump docs dependencies

docs/package-lock.json

Lines changed: 939 additions & 926 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

infrahub_sdk/graphql.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
VARIABLE_TYPE_MAPPING = ((str, "String!"), (int, "Int!"), (float, "Float!"), (bool, "Boolean!"))
99

1010

11-
def convert_to_graphql_as_string(value: str | bool | list | BaseModel | Enum | Any, convert_enum: bool = False) -> str: # noqa: PLR0911
11+
def convert_to_graphql_as_string(value: Any, convert_enum: bool = False) -> str: # noqa: PLR0911
12+
if value is None:
13+
return "null"
1214
if isinstance(value, str) and value.startswith("$"):
1315
return value
1416
if isinstance(value, Enum):

infrahub_sdk/node/node.py

Lines changed: 17 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,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

Comments
 (0)