From 407520486d146ecd1e6bfdbaf22982840b4b41d6 Mon Sep 17 00:00:00 2001 From: LucasG0 Date: Thu, 28 Aug 2025 16:11:22 +0200 Subject: [PATCH] Fix artifact validation --- backend/infrahub/generators/tasks.py | 15 +++++++------ backend/infrahub/git/tasks.py | 15 +++++++------ backend/infrahub/proposed_change/tasks.py | 26 ++++++++++++++--------- python_sdk | 2 +- 4 files changed, 35 insertions(+), 23 deletions(-) diff --git a/backend/infrahub/generators/tasks.py b/backend/infrahub/generators/tasks.py index b33468fc2b..715f4aa14c 100644 --- a/backend/infrahub/generators/tasks.py +++ b/backend/infrahub/generators/tasks.py @@ -168,6 +168,15 @@ async def request_generator_definition_run( client = get_client() + # Needs to be fetched before fetching group members otherwise `object` relationship would override + # existing node in client store without the `name` attribute due to #521 + existing_instances = await client.filters( + kind=InfrahubKind.GENERATORINSTANCE, + definition__ids=[model.generator_definition.definition_id], + include=["object"], + branch=model.branch, + ) + group = await client.get( kind=InfrahubKind.GENERICGROUP, prefetch_relationships=True, @@ -177,12 +186,6 @@ async def request_generator_definition_run( ) await group.members.fetch() - existing_instances = await client.filters( - kind=InfrahubKind.GENERATORINSTANCE, - definition__ids=[model.generator_definition.definition_id], - include=["object"], - branch=model.branch, - ) instance_by_member = {} for instance in existing_instances: instance_by_member[instance.object.peer.id] = instance.id diff --git a/backend/infrahub/git/tasks.py b/backend/infrahub/git/tasks.py index ecfee99ef9..362a600554 100644 --- a/backend/infrahub/git/tasks.py +++ b/backend/infrahub/git/tasks.py @@ -310,6 +310,15 @@ async def generate_request_artifact_definition( client = get_client() + # Needs to be fetched before fetching group members otherwise `object` relationship would override + # existing node in client store without the `name` attribute due to #521 + existing_artifacts = await client.filters( + kind=CoreArtifact, + definition__ids=[model.artifact_definition_id], + include=["object"], + branch=model.branch, + ) + artifact_definition = await client.get( kind=CoreArtifactDefinition, id=model.artifact_definition_id, branch=model.branch ) @@ -319,12 +328,6 @@ async def generate_request_artifact_definition( await group.members.fetch() current_members = [member.id for member in group.members.peers] - existing_artifacts = await client.filters( - kind=CoreArtifact, - definition__ids=[model.artifact_definition_id], - include=["object"], - branch=model.branch, - ) artifacts_by_member = {} for artifact in existing_artifacts: if artifact.object.id in current_members: diff --git a/backend/infrahub/proposed_change/tasks.py b/backend/infrahub/proposed_change/tasks.py index 0e3417c503..d5426cabe7 100644 --- a/backend/infrahub/proposed_change/tasks.py +++ b/backend/infrahub/proposed_change/tasks.py @@ -646,16 +646,19 @@ async def validate_artifacts_generation(model: RequestArtifactDefinitionCheck, c context=context, ) - await artifact_definition.targets.fetch() - group = artifact_definition.targets.peer - await group.members.fetch() - + # Needs to be fetched before fetching group members otherwise `object` relationship would override + # existing node in client store without the `name` attribute due to #521 existing_artifacts = await client.filters( kind=InfrahubKind.ARTIFACT, definition__ids=[model.artifact_definition.definition_id], include=["object"], branch=model.source_branch, ) + + await artifact_definition.targets.fetch() + group = artifact_definition.targets.peer + await group.members.fetch() + artifacts_by_member = {} for artifact in existing_artifacts: artifacts_by_member[artifact.object.peer.id] = artifact.id @@ -907,6 +910,15 @@ async def request_generator_definition_check(model: RequestGeneratorDefinitionCh context=context, ) + # Needs to be fetched before fetching group members otherwise `object` relationship would override + # existing node in client store without the `name` attribute due to #521 + existing_instances = await client.filters( + kind=InfrahubKind.GENERATORINSTANCE, + definition__ids=[model.generator_definition.definition_id], + include=["object"], + branch=model.source_branch, + ) + group = await client.get( kind=InfrahubKind.GENERICGROUP, prefetch_relationships=True, @@ -916,12 +928,6 @@ async def request_generator_definition_check(model: RequestGeneratorDefinitionCh ) await group.members.fetch() - existing_instances = await client.filters( - kind=InfrahubKind.GENERATORINSTANCE, - definition__ids=[model.generator_definition.definition_id], - include=["object"], - branch=model.source_branch, - ) instance_by_member = {} for instance in existing_instances: instance_by_member[instance.object.peer.id] = instance.id diff --git a/python_sdk b/python_sdk index 23a55e2e30..f4035f0f97 160000 --- a/python_sdk +++ b/python_sdk @@ -1 +1 @@ -Subproject commit 23a55e2e3013824c4bf7119c0e9657c27523ba8b +Subproject commit f4035f0f97843471d81a2f71d47561550fe7888c