Skip to content

Conversation

@dgarros
Copy link
Contributor

@dgarros dgarros commented Oct 12, 2025

Add the flags execute_in_proposed_change and execute_after_merge to CoreGeneratorDefinition to allow the user to control when a generator should be executed.

Related to opsmill/infrahub#7183

Summary by CodeRabbit

  • New Features

    • Added configurable options to control whether generators run within proposed changes and/or after merges (both enabled by default).
    • Generators now automatically adjust their grouping behavior based on post-merge execution settings for more accurate tracking and organization.
    • Repository views now expose related group objects, improving discoverability and navigation of generator-linked data.
  • Documentation

    • Descriptions provided for the new execution options to clarify behavior and defaults.

@coderabbitai
Copy link

coderabbitai bot commented Oct 12, 2025

Walkthrough

The change introduces two boolean configuration parameters—execute_in_proposed_change and execute_after_merge—across schema, protocols, generator, and control layers. These fields are added to InfrahubGeneratorDefinitionConfig and CoreGeneratorDefinition (and sync), wired through ctl/generator.py into InfrahubGenerator’s constructor, stored on the instance, and used at runtime to select a group type dynamically: "CoreGeneratorGroup" when execute_after_merge is true, otherwise "CoreGeneratorAwareGroup". New protocol classes CoreGeneratorAwareGroup and CoreGeneratorAwareGroupSync are added. CoreGenericRepository and its sync variant gain a groups_objects relationship field. No other control flow changes.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title concisely summarizes the main change by stating that flags are being added to CoreGeneratorDefinition to control generator execution timing, directly reflecting the pull request’s objective without unnecessary detail.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dga-20250909-generator-flags

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link

codecov bot commented Oct 12, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

@@                 Coverage Diff                  @@
##           infrahub-develop     #578      +/-   ##
====================================================
- Coverage             75.68%   75.27%   -0.41%     
====================================================
  Files                   108      108              
  Lines                 10276     9375     -901     
  Branches               2130     1864     -266     
====================================================
- Hits                   7777     7057     -720     
+ Misses                 1944     1823     -121     
+ Partials                555      495      -60     
Flag Coverage Δ
integration-tests 34.99% <86.66%> (-0.94%) ⬇️
python-3.10 48.45% <66.66%> (-1.51%) ⬇️
python-3.11 48.48% <66.66%> (-1.49%) ⬇️
python-3.12 48.45% <66.66%> (-1.49%) ⬇️
python-3.13 48.43% <66.66%> (-1.51%) ⬇️
python-3.9 47.10% <66.66%> (-1.34%) ⬇️
python-filler-3.12 24.29% <13.33%> (+0.56%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
infrahub_sdk/ctl/generator.py 50.90% <ø> (-4.36%) ⬇️
infrahub_sdk/generator.py 79.06% <100.00%> (+1.56%) ⬆️
infrahub_sdk/protocols.py 100.00% <100.00%> (ø)
infrahub_sdk/schema/repository.py 87.41% <100.00%> (+0.16%) ⬆️

... and 8 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Oct 13, 2025

Deploying infrahub-sdk-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: 0f5a1df
Status: ✅  Deploy successful!
Preview URL: https://89dab369.infrahub-sdk-python.pages.dev
Branch Preview URL: https://dga-20250909-generator-flags.infrahub-sdk-python.pages.dev

View logs

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
infrahub_sdk/ctl/generator.py (1)

53-110: Consider extracting shared generator execution logic.

Both code paths (lines 61-72 and 92-110) contain duplicated logic for:

  • Generator class instantiation with similar parameters
  • Client schema initialization (await generator._init_client.schema.all(branch=generator.branch_name))
  • Generator execution (await generator.run(identifier=generator_config.name, data=data))

Consider extracting this into a helper function to reduce duplication and improve maintainability.

Example refactor:

+async def _execute_generator(
+    generator_class,
+    generator_config,
+    client,
+    branch: str | None,
+    params: dict,
+    data: dict,
+) -> None:
+    generator = generator_class(
+        query=generator_config.query,
+        client=client,
+        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,
+    )
+    await generator._init_client.schema.all(branch=generator.branch_name)
+    await generator.run(identifier=generator_config.name, data=data)
+
 async def run(
     generator_name: str,
     path: str,  # noqa: ARG001
     debug: bool,
     list_available: bool,
     branch: str | None = None,
     variables: Optional[list[str]] = None,
 ) -> None:
     # ... existing code ...
     
     if variables_dict:
         data = execute_graphql_query(
             query=generator_config.query,
             variables_dict=variables_dict,
             branch=branch,
             debug=False,
             repository_config=repository_config,
         )
-        generator = generator_class(
-            query=generator_config.query,
-            client=client,
-            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)
-        await generator.run(identifier=generator_config.name, data=data)
+        await _execute_generator(
+            generator_class=generator_class,
+            generator_config=generator_config,
+            client=client,
+            branch=branch,
+            params=variables_dict,
+            data=data,
+        )
     else:
         # ... existing code for targets ...
         for member in targets._get_relationship_many(name="members").peers:
             # ... existing parameter setup ...
-            generator = generator_class(
-                query=generator_config.query,
-                client=client,
-                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(
                 query=generator_config.query,
                 variables_dict=check_parameter,
                 branch=branch,
                 debug=False,
                 repository_config=repository_config,
             )
-            await generator._init_client.schema.all(branch=generator.branch_name)
-            await generator.run(identifier=generator_config.name, data=data)
+            await _execute_generator(
+                generator_class=generator_class,
+                generator_config=generator_config,
+                client=client,
+                branch=branch,
+                params=params,
+                data=data,
+            )
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4322fb9 and ce91f11.

📒 Files selected for processing (1)
  • infrahub_sdk/ctl/generator.py (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

When implementing Infrahub checks, subclass InfrahubCheck and override validate(data); do not implement or rely on a check() method

Files:

  • infrahub_sdk/ctl/generator.py
infrahub_sdk/ctl/**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

infrahub_sdk/ctl/**/*.py: Build CLI commands with Typer
Organize and keep all CLI commands within infrahub_sdk/ctl/

Files:

  • infrahub_sdk/ctl/generator.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: integration-tests-latest-infrahub
  • GitHub Check: unit-tests (3.13)
  • GitHub Check: unit-tests (3.11)
  • GitHub Check: unit-tests (3.10)
  • GitHub Check: unit-tests (3.9)
  • GitHub Check: unit-tests (3.12)
🔇 Additional comments (2)
infrahub_sdk/ctl/generator.py (2)

67-68: LGTM! New flags correctly passed to generator.

The execute_in_proposed_change and execute_after_merge flags are properly passed from the generator configuration to the generator class constructor.


98-99: LGTM! Flags consistently applied in targets path.

The new execution flags are correctly passed to the generator constructor in the targets iteration path, maintaining consistency with the variables_dict code path.

@dgarros dgarros requested a review from a team October 13, 2025 10:52
Copy link
Contributor

@ogenstad ogenstad left a comment

Choose a reason for hiding this comment

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

LGTM aside from the comments on the additional attribute definitions outside of __init__

@dgarros dgarros force-pushed the dga-20250909-generator-flags branch from ce91f11 to c3dc786 Compare October 13, 2025 12:49
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
infrahub_sdk/generator.py (2)

19-25: Consider removing redundant class-level attribute declarations.

These class-level type annotations duplicate the typing already present in __init__ (lines 27-41). As noted in the previous review comment, they provide limited value and may cause confusion if there's a mismatch between the class-level hints and the actual initialization.

If you decide to keep them for documentation purposes, consider adding a comment explaining that these are instance attributes initialized in __init__.


96-99: LGTM, but consider adding a clarifying comment.

The group type selection logic is correct: generators executing after merge use CoreGeneratorGroup, while those executing in proposed changes use CoreGeneratorAwareGroup. However, the relationship between the flag name and the group type choice is not immediately obvious.

Consider adding a brief comment explaining the distinction:

+        # Use CoreGeneratorAwareGroup for generators running in proposed changes,
+        # CoreGeneratorGroup for post-merge execution
         group_type = "CoreGeneratorGroup" if self.execute_after_merge else "CoreGeneratorAwareGroup"
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ce91f11 and c3dc786.

📒 Files selected for processing (5)
  • infrahub_sdk/ctl/generator.py (2 hunks)
  • infrahub_sdk/generator.py (4 hunks)
  • infrahub_sdk/operation.py (1 hunks)
  • infrahub_sdk/protocols.py (6 hunks)
  • infrahub_sdk/schema/repository.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • infrahub_sdk/ctl/generator.py
  • infrahub_sdk/operation.py
🧰 Additional context used
📓 Path-based instructions (1)
**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

When implementing Infrahub checks, subclass InfrahubCheck and override validate(data); do not implement or rely on a check() method

Files:

  • infrahub_sdk/schema/repository.py
  • infrahub_sdk/protocols.py
  • infrahub_sdk/generator.py
🧬 Code graph analysis (2)
infrahub_sdk/protocols.py (2)
infrahub_sdk/node/relationship.py (2)
  • RelationshipManager (100-220)
  • RelationshipManagerSync (223-343)
infrahub_sdk/protocols_base.py (1)
  • BooleanOptional (147-148)
infrahub_sdk/generator.py (2)
infrahub_sdk/client.py (3)
  • request_context (188-189)
  • request_context (192-193)
  • start_tracking (195-214)
infrahub_sdk/context.py (1)
  • RequestContext (10-13)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: unit-tests (3.13)
  • GitHub Check: unit-tests (3.12)
  • GitHub Check: unit-tests (3.10)
  • GitHub Check: unit-tests (3.11)
  • GitHub Check: integration-tests-latest-infrahub
🔇 Additional comments (4)
infrahub_sdk/schema/repository.py (1)

99-106: LGTM!

The new boolean flags are well-defined with sensible defaults that maintain backward compatibility (generators execute in both phases by default). The field names and descriptions clearly communicate their purpose.

infrahub_sdk/protocols.py (3)

134-134: LGTM!

The new groups_objects relationship follows the existing pattern for relationship definitions on CoreGenericRepository.


359-360: LGTM!

The new CoreGeneratorAwareGroup class is correctly defined as a protocol subclass of CoreGroup, matching the pattern used by other group variants in this file (e.g., CoreGeneratorGroup, CoreStandardGroup).


374-375: LGTM!

The execution control flags are correctly defined as BooleanOptional fields, allowing them to be nullable in the protocol layer while the configuration layer enforces defaults. This separation is intentional and follows the existing pattern for optional boolean fields in this codebase.

Comment on lines +37 to +30
execute_in_proposed_change: bool = True,
execute_after_merge: bool = True,
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.

@dgarros dgarros force-pushed the dga-20250909-generator-flags branch from c3dc786 to 0f5a1df Compare October 14, 2025 03:56
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
infrahub_sdk/schema/repository.py (1)

99-106: Ensure at least one execution flag is enabled
Currently both flags default to True, but setting execute_in_proposed_change and execute_after_merge to False silences the generator. Document this behavior or add a Pydantic root validator in infrahub_sdk/schema/repository.py to enforce that at least one of these flags is True.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c3dc786 and 0f5a1df.

📒 Files selected for processing (4)
  • infrahub_sdk/ctl/generator.py (2 hunks)
  • infrahub_sdk/generator.py (3 hunks)
  • infrahub_sdk/protocols.py (6 hunks)
  • infrahub_sdk/schema/repository.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • infrahub_sdk/protocols.py
  • infrahub_sdk/generator.py
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

When implementing Infrahub checks, subclass InfrahubCheck and override validate(data); do not implement or rely on a check() method

Files:

  • infrahub_sdk/schema/repository.py
  • infrahub_sdk/ctl/generator.py
infrahub_sdk/ctl/**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

infrahub_sdk/ctl/**/*.py: Build CLI commands with Typer
Organize and keep all CLI commands within infrahub_sdk/ctl/

Files:

  • infrahub_sdk/ctl/generator.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: unit-tests (3.9)
  • GitHub Check: unit-tests (3.10)
  • GitHub Check: unit-tests (3.11)
  • GitHub Check: unit-tests (3.13)
  • GitHub Check: unit-tests (3.12)
  • GitHub Check: integration-tests-latest-infrahub
🔇 Additional comments (2)
infrahub_sdk/ctl/generator.py (2)

67-68: LGTM!

The new execution control parameters are correctly passed from the generator configuration to the generator class constructor, following the established pattern for other configuration parameters.


98-99: LGTM!

The execution control parameters are consistently passed in both code paths (variables_dict present and targets path), ensuring uniform behavior across different execution scenarios.

@dgarros dgarros merged commit a6c6ac6 into infrahub-develop Oct 14, 2025
20 checks passed
@dgarros dgarros deleted the dga-20250909-generator-flags branch October 14, 2025 04:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants