Skip to content

Commit 0b9ff47

Browse files
committed
Fix ability to construct HFID for upsert mutations where a number attribute is used
Fixes #4460
1 parent b4ee01b commit 0b9ff47

File tree

4 files changed

+56
-1
lines changed

4 files changed

+56
-1
lines changed

backend/infrahub/graphql/mutations/node_getter/by_hfid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ async def get_node(
5050
if attribute_path.is_type_attribute and attribute_path.attribute_schema:
5151
hfid_component = data[attribute_path.attribute_schema.name].get(attribute_path.attribute_property_name)
5252
if hfid_component is not None:
53-
hfid.append(hfid_component)
53+
hfid.append(str(hfid_component))
5454
if (
5555
attribute_path.relationship_schema
5656
and attribute_path.related_schema

backend/tests/constants/kind.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
CAR = "TestingCar"
22
MANUFACTURER = "TestingManufacturer"
33
PERSON = "TestingPerson"
4+
TICKET = "TestingTicket"

backend/tests/unit/graphql/test_mutation_upsert.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55
from infrahub.core.branch import Branch
66
from infrahub.core.manager import NodeManager
77
from infrahub.core.node import Node
8+
from infrahub.core.registry import registry
9+
from infrahub.core.schema import SchemaRoot
810
from infrahub.database import InfrahubDatabase
911
from infrahub.graphql import prepare_graphql_params
12+
from tests.constants import TestKind
13+
from tests.helpers.schema import TICKET
1014

1115

1216
async def test_upsert_existing_simple_object_by_id(db: InfrahubDatabase, person_john_main: Node, branch: Branch):
@@ -393,3 +397,52 @@ async def test_with_constructed_hfid(db: InfrahubDatabase, default_branch, anima
393397
"name": {"value": "Ghost"},
394398
"weight": {"value": updated_weight},
395399
}
400+
401+
402+
async def test_with_constructed_hfid_with_numbers(
403+
db: InfrahubDatabase, default_branch: Branch, data_schema: None
404+
) -> None:
405+
"""Validate that we can construct an HFID out of the payload without specifying all parts."""
406+
registry.schema.register_schema(schema=SchemaRoot(nodes=[TICKET]), branch=default_branch.name)
407+
408+
first_ticket = await Node.init(schema=TestKind.TICKET, db=db)
409+
await first_ticket.new(db=db, title="first", ticket_id=1, description="Add more info")
410+
await first_ticket.save(db=db)
411+
412+
query = """
413+
mutation UpsertTicket {
414+
TestingTicketUpsert(data: {
415+
title: { value: "first" },
416+
ticket_id: { value: 1 },
417+
description: { value: "Here is the update" },
418+
}) {
419+
ok
420+
object {
421+
id
422+
title {
423+
value
424+
}
425+
description {
426+
value
427+
}
428+
}
429+
}
430+
}
431+
"""
432+
gql_params = prepare_graphql_params(db=db, include_subscription=False, branch=default_branch)
433+
434+
update_result = await graphql(
435+
schema=gql_params.schema,
436+
source=query,
437+
context_value=gql_params.context,
438+
root_value=None,
439+
)
440+
441+
assert update_result.errors is None
442+
assert update_result.data
443+
assert update_result.data["TestingTicketUpsert"]["ok"] is True
444+
assert update_result.data["TestingTicketUpsert"]["object"] == {
445+
"title": {"value": "first"},
446+
"description": {"value": "Here is the update"},
447+
"id": first_ticket.id,
448+
}

changelog/4460.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix ability to construct HFID for upsert mutations where a number attribute is used.

0 commit comments

Comments
 (0)