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
4 changes: 4 additions & 0 deletions infrahub_sdk/ctl/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ async def run(
branch=branch or "",
params=variables_dict,
convert_query_response=generator_config.convert_query_response,
execute_in_proposed_change=generator_config.execute_in_proposed_change,
execute_after_merge=generator_config.execute_after_merge,
infrahub_node=InfrahubNode,
)
await generator._init_client.schema.all(branch=generator.branch_name)
Expand Down Expand Up @@ -93,6 +95,8 @@ async def run(
branch=branch or "",
params=params,
convert_query_response=generator_config.convert_query_response,
execute_in_proposed_change=generator_config.execute_in_proposed_change,
execute_after_merge=generator_config.execute_after_merge,
infrahub_node=InfrahubNode,
)
data = execute_graphql_query(
Expand Down
8 changes: 7 additions & 1 deletion infrahub_sdk/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def __init__(
generator_instance: str = "",
params: dict | None = None,
convert_query_response: bool = False,
execute_in_proposed_change: bool = True,
execute_after_merge: bool = True,
Comment on lines +29 to +30
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Verify that execute_in_proposed_change is used by calling code.

The execute_in_proposed_change flag is accepted, stored, but never used within this file's logic. Only execute_after_merge influences the group_type selection (line 96). Ensure that calling code (likely in infrahub_sdk/ctl/generator.py) checks execute_in_proposed_change to determine whether to invoke run() during the proposed change phase.

Run the following script to verify usage of execute_in_proposed_change:

Also applies to: 57-58


🏁 Script executed:

#!/bin/bash
# Description: Find usages of execute_in_proposed_change to confirm it's checked by orchestration code

# Search for reads of the attribute
rg -n "\.execute_in_proposed_change" --type=py

Length of output: 335


🏁 Script executed:

#!/bin/bash
# Show context for execute_in_proposed_change in ctl/generator.py
rg -nC3 "execute_in_proposed_change" --type=py infrahub_sdk/ctl/generator.py

Length of output: 762


Remove or implement execute_in_proposed_change, it’s never used.
The flag is accepted and passed through from CLI (infrahub_sdk/ctl/generator.py:67,98) into the core generator (infrahub_sdk/generator.py:57) but never read—only execute_after_merge affects behavior. Either drop the parameter or add logic to act on it during the proposed‐change phase.

🤖 Prompt for AI Agents
In infrahub_sdk/generator.py around lines 37-38, the parameter
execute_in_proposed_change is accepted but never used; either remove this unused
parameter from the function signature and update callers
(infrahub_sdk/ctl/generator.py at the CLI call sites) to stop passing it, or
implement the missing logic: add a conditional branch in the proposed-change
execution path that checks execute_in_proposed_change and performs the intended
execution during the proposed-change phase (mirroring how execute_after_merge is
handled), and update/add unit tests and documentation accordingly.

logger: logging.Logger | None = None,
request_context: RequestContext | None = None,
) -> None:
Expand All @@ -44,6 +46,8 @@ def __init__(
self._client: InfrahubClient | None = None
self.logger = logger if logger else logging.getLogger("infrahub.tasks")
self.request_context = request_context
self.execute_in_proposed_change = execute_in_proposed_change
self.execute_after_merge = execute_after_merge

@property
def subscribers(self) -> list[str] | None:
Expand Down Expand Up @@ -81,8 +85,10 @@ async def run(self, identifier: str, data: dict | None = None) -> None:
unpacked = data.get("data") or data
await self.process_nodes(data=unpacked)

group_type = "CoreGeneratorGroup" if self.execute_after_merge else "CoreGeneratorAwareGroup"

async with self._init_client.start_tracking(
identifier=identifier, params=self.params, delete_unused_nodes=True, group_type="CoreGeneratorGroup"
identifier=identifier, params=self.params, delete_unused_nodes=True, group_type=group_type
) as self.client:
await self.generate(data=unpacked)

Expand Down
14 changes: 14 additions & 0 deletions infrahub_sdk/protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ class CoreGenericRepository(CoreNode):
queries: RelationshipManager
checks: RelationshipManager
generators: RelationshipManager
groups_objects: RelationshipManager


class CoreGroup(CoreNode):
Expand Down Expand Up @@ -355,6 +356,10 @@ class CoreGeneratorAction(CoreAction):
generator: RelatedNode


class CoreGeneratorAwareGroup(CoreGroup):
pass


class CoreGeneratorCheck(CoreCheck):
instance: String

Expand All @@ -366,6 +371,8 @@ class CoreGeneratorDefinition(CoreTaskTarget):
file_path: String
class_name: String
convert_query_response: BooleanOptional
execute_in_proposed_change: BooleanOptional
execute_after_merge: BooleanOptional
query: RelatedNode
repository: RelatedNode
targets: RelatedNode
Expand Down Expand Up @@ -681,6 +688,7 @@ class CoreGenericRepositorySync(CoreNodeSync):
queries: RelationshipManagerSync
checks: RelationshipManagerSync
generators: RelationshipManagerSync
groups_objects: RelationshipManagerSync


class CoreGroupSync(CoreNodeSync):
Expand Down Expand Up @@ -905,6 +913,10 @@ class CoreGeneratorActionSync(CoreActionSync):
generator: RelatedNodeSync


class CoreGeneratorAwareGroupSync(CoreGroupSync):
pass


class CoreGeneratorCheckSync(CoreCheckSync):
instance: String

Expand All @@ -916,6 +928,8 @@ class CoreGeneratorDefinitionSync(CoreTaskTargetSync):
file_path: String
class_name: String
convert_query_response: BooleanOptional
execute_in_proposed_change: BooleanOptional
execute_after_merge: BooleanOptional
query: RelatedNodeSync
repository: RelatedNodeSync
targets: RelatedNodeSync
Expand Down
8 changes: 8 additions & 0 deletions infrahub_sdk/schema/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ class InfrahubGeneratorDefinitionConfig(InfrahubRepositoryConfigElement):
default=False,
description="Decide if the generator should convert the result of the GraphQL query to SDK InfrahubNode objects.",
)
execute_in_proposed_change: bool = Field(
default=True,
description="Decide if the generator should execute in a proposed change.",
)
execute_after_merge: bool = Field(
default=True,
description="Decide if the generator should execute after a merge.",
)

def load_class(self, import_root: str | None = None, relative_path: str | None = None) -> type[InfrahubGenerator]:
module = import_module(module_path=self.file_path, import_root=import_root, relative_path=relative_path)
Expand Down