Skip to content

Commit 64b5dff

Browse files
committed
Fix regression with Node update and update to 1.4.1
1 parent 19b0899 commit 64b5dff

File tree

7 files changed

+328
-84
lines changed

7 files changed

+328
-84
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ This project uses [*towncrier*](https://towncrier.readthedocs.io/) and the chang
1111

1212
<!-- towncrier release notes start -->
1313

14+
## [1.4.1](https://github.com/opsmill/infrahub-sdk-python/tree/v1.3.0) - 2025-01-05
15+
16+
### Fixed
17+
18+
- Fixes an issue introduced in 1.4 that would prevent a node with relationship of cardinality one from being updated.
19+
1420
## [1.4.0](https://github.com/opsmill/infrahub-sdk-python/tree/v1.4.0) - 2025-01-03
1521

1622
### Changed

infrahub_sdk/node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ def _strip_unmodified_dict(data: dict, original_data: dict, variables: dict, ite
904904
variables.pop(variable_key)
905905

906906
# TODO: I do not feel _great_ about this
907-
if not data_item and data_item != []:
907+
if not data_item and data_item != [] and item in data:
908908
data.pop(item)
909909

910910
def _strip_unmodified(self, data: dict, variables: dict) -> tuple[dict, dict]:

infrahub_sdk/testing/schemas/car_person.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ async def person_joe(self, client: InfrahubClient, person_joe_data: TestingPerso
170170
await obj.save()
171171
return obj
172172

173+
@pytest.fixture(scope="class")
174+
async def person_jane(self, client: InfrahubClient, person_jane_data: TestingPersonData) -> InfrahubNode:
175+
obj = await client.create(**asdict(person_jane_data))
176+
await obj.save()
177+
return obj
178+
173179
@pytest.fixture(scope="class")
174180
async def manufacturer_mercedes(
175181
self, client: InfrahubClient, manufacturer_mercedes_data: TestingManufacturerData
@@ -202,6 +208,12 @@ async def tag_red(self, client: InfrahubClient) -> InfrahubNode:
202208
await obj.save()
203209
return obj
204210

211+
@pytest.fixture(scope="class")
212+
async def tag_green(self, client: InfrahubClient) -> InfrahubNode:
213+
obj = await client.create(kind=BUILTIN_TAG, name="Green")
214+
await obj.save()
215+
return obj
216+
205217
async def create_persons(self, client: InfrahubClient, branch: str) -> list[InfrahubNode]:
206218
john = await client.create(kind=TESTING_PERSON, name="John Doe", branch=branch)
207219
await john.save()

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
[project]
22
name = "infrahub-sdk"
3-
version = "1.4.0"
3+
version = "1.4.1"
44
requires-python = ">=3.9"
55

66
[tool.poetry]
77
name = "infrahub-sdk"
8-
version = "1.4.0"
8+
version = "1.4.1"
99
description = "Python Client to interact with Infrahub"
1010
authors = ["OpsMill <[email protected]>"]
1111
readme = "README.md"

tests/integration/test_node.py

Lines changed: 13 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -143,48 +143,31 @@ async def test_node_update(
143143
initial_schema: None,
144144
manufacturer_mercedes,
145145
person_joe,
146+
person_jane,
146147
car_golf,
147148
tag_blue,
148149
tag_red,
150+
tag_green,
149151
):
150152
car_golf.color.value = "White"
151153
await car_golf.tags.fetch()
152154
car_golf.tags.add(tag_blue.id)
153155
car_golf.tags.add(tag_red.id)
154156
await car_golf.save()
155157

156-
node_after = await client.get(kind=TESTING_CAR, id=car_golf.id)
157-
assert node_after.color.value == "White"
158-
await node_after.tags.fetch()
159-
assert len(node_after.tags.peers) == 2
158+
car2 = await client.get(kind=TESTING_CAR, id=car_golf.id)
159+
assert car2.color.value == "White"
160+
await car2.tags.fetch()
161+
assert len(car2.tags.peers) == 2
160162

161-
# async def test_node_update_2(
162-
# self,
163-
# db: InfrahubDatabase,
164-
# client: InfrahubClient,
165-
# init_db_base,
166-
# load_builtin_schema,
167-
# tag_green: Node,
168-
# tag_red: Node,
169-
# tag_blue: Node,
170-
# gqlquery02: Node,
171-
# repo99: Node,
172-
# ):
173-
# node = await client.get(kind="CoreGraphQLQuery", name__value="query02")
174-
# assert node.id is not None
163+
car2.owner = person_jane.id
164+
car2.tags.add(tag_green.id)
165+
car2.tags.remove(tag_red.id)
166+
await car2.save()
175167

176-
# node.name.value = "query021"
177-
# node.repository = repo99.id
178-
# node.tags.add(tag_green.id)
179-
# node.tags.remove(tag_red.id)
180-
# await node.save()
181-
182-
# nodedb = await NodeManager.get_one(id=node.id, db=db, include_owner=True, include_source=True)
183-
# repodb = await nodedb.repository.get_peer(db=db)
184-
# assert repodb.id == repo99.id
185-
186-
# tags = await nodedb.tags.get(db=db)
187-
# assert sorted([tag.peer_id for tag in tags]) == sorted([tag_green.id, tag_blue.id])
168+
car3 = await client.get(kind=TESTING_CAR, id=car_golf.id)
169+
await car3.tags.fetch()
170+
assert sorted([tag.id for tag in car3.tags.peers]) == sorted([tag_green.id, tag_blue.id])
188171

189172
# async def test_node_update_3_idempotency(
190173
# self,
@@ -222,21 +205,6 @@ async def test_node_update(
222205
# assert "query" not in second_update["data"]["data"]
223206
# assert not second_update["variables"]
224207

225-
# async def test_convert_node(
226-
# self,
227-
# db: InfrahubDatabase,
228-
# client: InfrahubClient,
229-
# location_schema,
230-
# init_db_base,
231-
# load_builtin_schema,
232-
# location_cdg: Node,
233-
# ):
234-
# data = await location_cdg.to_graphql(db=db)
235-
# node = InfrahubNode(client=client, schema=location_schema, data=data)
236-
237-
# # pylint: disable=no-member
238-
# assert node.name.value == "cdg01"
239-
240208
# async def test_relationship_manager_errors_without_fetch(self, client: InfrahubClient, load_builtin_schema):
241209
# organization = await client.create("TestOrganization", name="organization-1")
242210
# await organization.save()

tests/unit/sdk/conftest.py

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,47 @@ async def location_data02_no_pagination():
373373

374374
@pytest.fixture
375375
async def location_data01():
376+
data = {
377+
"node": {
378+
"__typename": "BuiltinLocation",
379+
"id": "llllllll-llll-llll-llll-llllllllllll",
380+
"display_label": "dfw1",
381+
"name": {
382+
"value": "DFW",
383+
},
384+
"description": {
385+
"value": None,
386+
},
387+
"type": {
388+
"value": "SITE",
389+
},
390+
"primary_tag": {
391+
"node": {
392+
"id": "rrrrrrrr-rrrr-rrrr-rrrr-rrrrrrrrrrrr",
393+
"display_label": "red",
394+
"__typename": "BuiltinTag",
395+
},
396+
},
397+
"tags": {
398+
"count": 1,
399+
"edges": [
400+
{
401+
"node": {
402+
"id": "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
403+
"display_label": "blue",
404+
"__typename": "BuiltinTag",
405+
},
406+
}
407+
],
408+
},
409+
}
410+
}
411+
412+
return data
413+
414+
415+
@pytest.fixture
416+
async def location_data01_property():
376417
data = {
377418
"node": {
378419
"__typename": "BuiltinLocation",
@@ -438,6 +479,47 @@ async def location_data01():
438479

439480
@pytest.fixture
440481
async def location_data02():
482+
data = {
483+
"node": {
484+
"__typename": "BuiltinLocation",
485+
"id": "llllllll-llll-llll-llll-llllllllllll",
486+
"display_label": "dfw1",
487+
"name": {
488+
"value": "dfw1",
489+
},
490+
"description": {
491+
"value": None,
492+
},
493+
"type": {
494+
"value": "SITE",
495+
},
496+
"primary_tag": {
497+
"node": {
498+
"id": "rrrrrrrr-rrrr-rrrr-rrrr-rrrrrrrrrrrr",
499+
"display_label": "red",
500+
"__typename": "BuiltinTag",
501+
},
502+
},
503+
"tags": {
504+
"count": 1,
505+
"edges": [
506+
{
507+
"node": {
508+
"id": "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
509+
"display_label": "blue",
510+
"__typename": "BuiltinTag",
511+
},
512+
}
513+
],
514+
},
515+
}
516+
}
517+
518+
return data
519+
520+
521+
@pytest.fixture
522+
async def location_data02_property():
441523
data = {
442524
"node": {
443525
"__typename": "BuiltinLocation",
@@ -517,6 +599,28 @@ async def location_data02():
517599
return data
518600

519601

602+
@pytest.fixture
603+
async def rfile_userdata01():
604+
return {
605+
"name": {"value": "rfile01"},
606+
"template_path": {"value": "mytemplate.j2"},
607+
"query": {"id": "qqqqqqqq"},
608+
"repository": {"id": "rrrrrrrr"},
609+
"tags": [{"id": "t1t1t1t1"}, "t2t2t2t2"],
610+
}
611+
612+
613+
@pytest.fixture
614+
async def rfile_userdata01_property():
615+
return {
616+
"name": {"value": "rfile01", "is_protected": True, "source": "ffffffff"},
617+
"template_path": {"value": "mytemplate.j2"},
618+
"query": {"id": "qqqqqqqq", "source": "ffffffff", "owner": "ffffffff", "is_protected": True},
619+
"repository": {"id": "rrrrrrrr", "source": "ffffffff", "owner": "ffffffff"},
620+
"tags": [{"id": "t1t1t1t1"}, "t2t2t2t2"],
621+
}
622+
623+
520624
@pytest.fixture
521625
async def tag_schema() -> NodeSchemaAPI:
522626
data = {

0 commit comments

Comments
 (0)