Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions backend/infrahub/generators/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like adding the same comment in 4 different places...
but I also cannot think of a better option right now

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,
Expand All @@ -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
Expand Down
15 changes: 9 additions & 6 deletions backend/infrahub/git/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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:
Expand Down
26 changes: 16 additions & 10 deletions backend/infrahub/proposed_change/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down
Loading