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
19 changes: 13 additions & 6 deletions infrahub_sdk/schema/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,28 @@ class InfrahubGeneratorDefinitionConfig(InfrahubRepositoryConfigElement):
file_path: Path = Field(..., description="The file within the repository with the generator code.")
query: str = Field(..., description="The GraphQL query to use as input.")
parameters: dict[str, Any] = Field(
default_factory=dict, description="The input parameters required to run this check"
default_factory=dict,
description="Maps GraphQL query variable names to target object attribute paths using double-underscore notation.",
)
Comment on lines 90 to +93
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Search for code that parses double-underscore notation in parameters

# Search for patterns that might indicate double-underscore parsing
rg -n -C5 '__' --type=py --glob='**/generator*.py' --glob='**/repository*.py'

# Look for methods that process params/parameters in generator classes
ast-grep --pattern 'def $FUNC($$$) {
  $$$
  params
  $$$
}'

Repository: opsmill/infrahub-sdk-python

Length of output: 11179


🏁 Script executed:

# Search for InfrahubGeneratorDefinitionConfig usage and definition
rg -n "InfrahubGeneratorDefinitionConfig" --type=py -A 5 -B 2

# Look at the actual parameters field definition and usage
rg -n "parameters" --type=py infrahub_sdk/schema/repository.py

# Check for any documentation or tests about how parameters work
fd -e py -e md | xargs rg -l "parameters.*GraphQL\|parameters.*double" 2>/dev/null | head -10

Repository: opsmill/infrahub-sdk-python

Length of output: 3468


🏁 Script executed:

# Look at the full definition of InfrahubGeneratorDefinitionConfig
sed -n '84,115p' infrahub_sdk/schema/repository.py

# Search for how params/parameters are used in generator execution
rg -n "self.params\|parameters" infrahub_sdk/generator.py -B 3 -A 3

# Look for any transformation or parsing of parameters
rg -n "\.get\(|split\(|parse" infrahub_sdk/generator.py --type=py -A 2 -B 2

Repository: opsmill/infrahub-sdk-python

Length of output: 2081


🏁 Script executed:

# Search for actual examples or tests showing how the parameters field is used
rg -n "parameters.*=" --type=py -B 2 -A 2 | grep -A 5 -B 5 "InfrahubGeneratorDefinitionConfig\|generator.*parameters" | head -50

# Look at how collect_data and other methods use self.params
sed -n '45,80p' infrahub_sdk/generator.py

# Search for any documentation or examples in md/yaml files
fd -e md -e yaml | xargs grep -l "generator" 2>/dev/null | head -5

Repository: opsmill/infrahub-sdk-python

Length of output: 1392


🏁 Script executed:

# Find where self.params is initialized
rg -n "self.params\s*=" --type=py -B 5 -A 5

# Look for InfrahubOperation class definition
rg -n "class InfrahubOperation" --type=py -A 30

# Check if there's any initialization from InfrahubGeneratorDefinitionConfig
rg -n "InfrahubGenerator\|InfrahubOperation" infrahub_sdk/generator.py | head -20

Repository: opsmill/infrahub-sdk-python

Length of output: 4037


🏁 Script executed:

# Search for tests or examples using InfrahubGeneratorDefinitionConfig with parameters
fd -e py | xargs grep -l "InfrahubGeneratorDefinitionConfig\|generator.*config" 2>/dev/null | head -10

# Look at tests directory for generator tests
fd test.*generator -type f

# Search for any usage examples in comments or docstrings
rg -n "parameters.*:" --type=py -B 5 -A 5 infrahub_sdk/schema/repository.py

Repository: opsmill/infrahub-sdk-python

Length of output: 2254


🏁 Script executed:

# Look at how generator definitions are actually used in ctl/generator.py
sed -n '1,100p' infrahub_sdk/ctl/generator.py

# Search for examples of generator configs in test files
fd test -type d

# Look for any YAML examples of generators
fd -e yaml -e yml | xargs grep -l "generator" 2>/dev/null | head -5

Repository: opsmill/infrahub-sdk-python

Length of output: 4029


🏁 Script executed:

# Get more context from ctl/generator.py around the parameter usage
sed -n '85,100p' infrahub_sdk/ctl/generator.py

# Search for any double-underscore usage in context of parameters or attributes
rg -n "identifier\|check_parameter\|params" infrahub_sdk/ctl/generator.py -B 2 -A 2 | head -60

Repository: opsmill/infrahub-sdk-python

Length of output: 881


🏁 Script executed:

# Check if there's any double-underscore transformation in getattr or attribute access
rg -n "split.*__\|\.replace.*__\|parse.*__" --type=py

# Look more carefully at how parameters are used in the actual generator run
rg -n "params\|parameters" infrahub_sdk/ctl/generator.py -A 3 -B 3

# Check if there's any documentation about this in README or docs
find . -name "*.md" | xargs grep -i "generator.*parameter\|double.*underscore" 2>/dev/null

Repository: opsmill/infrahub-sdk-python

Length of output: 55


🏁 Script executed:

# Search more carefully for double-underscore pattern in context of parameters/attributes
rg "parameters" infrahub_sdk/ctl/generator.py -C 10

# Check if parameters are actually transformed or mapped anywhere
rg -n "\.keys\(\)|identifier|check_parameter" infrahub_sdk/ctl/generator.py

# Look at the complete generator config loading
sed -n '40,100p' infrahub_sdk/ctl/generator.py

Repository: opsmill/infrahub-sdk-python

Length of output: 3964


Correct the inaccurate parameters field description.

The current description states parameters "Maps GraphQL query variable names to target object attribute paths using double-underscore notation." However, investigation of infrahub_sdk/ctl/generator.py and infrahub_sdk/generator.py reveals that parameter keys are used directly as Python attribute names (via getattr(member.peer, identifier)) and passed to GraphQL queries without any parsing of double-underscore notation. No such transformation logic exists in the codebase.

Revise the description to accurately reflect that parameter keys represent member object attribute names used to extract values passed as GraphQL variables.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@infrahub_sdk/schema/repository.py` around lines 90 - 93, The Field
description for the parameters attribute is inaccurate; update the
Field(description=...) for the parameters variable in the repository.Schema
class so it says that keys are member object attribute names used to extract
values (via getattr on member.peer) and those extracted values are passed
directly as GraphQL variables, rather than describing any double-underscore path
parsing. Reference the parameters Field and the usage via getattr(member.peer,
identifier) in generator modules when editing the text.

targets: str = Field(
...,
description="Name of the CoreStandardGroup whose members become individual Generator targets. One run is created per group member.",
)
class_name: str = Field(
default="Generator",
description="The name of the Python class within file_path that extends InfrahubGenerator.",
)
targets: str = Field(..., description="The group to target when running this generator")
class_name: str = Field(default="Generator", description="The name of the generator class to run.")
convert_query_response: bool = Field(
default=False,
description="Decide if the generator should convert the result of the GraphQL query to SDK InfrahubNode objects.",
description="When true, converts the raw GraphQL dict into SDK InfrahubNode objects accessible via self.nodes and self.store.",
)
execute_in_proposed_change: bool = Field(
default=True,
description="Decide if the generator should execute in a proposed change.",
description="When true (default), the Generator runs as a CI check during proposed changes.",
)
execute_after_merge: bool = Field(
default=True,
description="Decide if the generator should execute after a merge.",
description="When true (default), the Generator runs after a branch merge. Set to false for Generators that only run via event triggers.",
)

def load_class(self, import_root: str | None = None, relative_path: str | None = None) -> type[InfrahubGenerator]:
Expand Down
6 changes: 3 additions & 3 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.