Skip to content

fix: run infrahubctl generator on target kinds without a name attribute - #1291

Open
pthmas wants to merge 1 commit into
stablefrom
issue-1289
Open

fix: run infrahubctl generator on target kinds without a name attribute#1291
pthmas wants to merge 1 commit into
stablefrom
issue-1289

Conversation

@pthmas

@pthmas pthmas commented Aug 27, 2026

Copy link
Copy Markdown

Why

infrahubctl generator <generator> exits immediately with Error: The node doesn't have an attribute for name when the generator's targets group holds members of a kind that has no name attribute. The generator never runs. The same generator works server-side in a proposed change, because the CLI is the only path that builds its per-target values this way. Reported by a customer whose target kind is a firewall rule identified by rule_id.

Goal: the CLI runs the generator once per group member whatever attributes the target kind happens to have, deriving the per-target values the same way Infrahub does.

Closes #1289

What changed

Behavioral changes:

  • Target kinds without a name attribute no longer abort the run.
  • Every declared parameter now reaches the query, not just the first one.
  • A CLI run and a server run of the same generator against the same target now share a tracking group, so each cleans up the other's stale nodes.

Implementation notes: the per-target values now come from member.peer.extract(params=generator_config.parameters) — the same call Infrahub makes at backend/infrahub/generators/tasks.py:246. That resolves each parameter's declared path (rule_id: rule_id__value) rather than reading the parameter key as an attribute name, which only worked when the two coincided. For parameters: {name: "name__value"} the result is identical to before, so existing tracking groups keep their names.

What stayed the same: no CLI signature change, no schema change, server-side execution untouched.

How to review

infrahub_sdk/ctl/generator.py — the group loop now resolves the parameters mapping in one call, and the hand-rolled first-key lookup above it is gone. The resolved dict serves as both the query variables and the generator params, as it does server-side.

How to test

uv run pytest tests/unit/ctl/test_generator.py
uv run invoke format lint-code

Manual: define a kind with no name attribute, add nodes to a CoreStandardGroup, point a generator definition's targets at it with a parameter on one of that kind's own attributes, and run infrahubctl generator <generator> with no variables. Before: exits with The node doesn't have an attribute for name. After: one run per member.

Impact & rollout

  • Backward compatibility: for parameters: {name: "name__value"}, the resolved values are identical to before — same tracking group names.
  • Config/env changes: none.
  • Deployment notes: safe to release.

Checklist

  • Tests added/updated
  • Changelog entry added
  • External docs updated — not needed, no interface change
  • Internal .md docs updated — not needed

@pthmas
pthmas requested a review from a team as a code owner August 27, 2026 10:19
@pthmas pthmas added the type/bug Something isn't working as expected label Aug 27, 2026
@pthmas pthmas self-assigned this Aug 27, 2026
@codecov

codecov Bot commented Aug 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

@@            Coverage Diff             @@
##           stable    #1291      +/-   ##
==========================================
+ Coverage   84.24%   84.37%   +0.13%     
==========================================
  Files         147      147              
  Lines       13066    13037      -29     
  Branches     1940     1928      -12     
==========================================
- Hits        11007    11000       -7     
+ Misses       1494     1477      -17     
+ Partials      565      560       -5     
Flag Coverage Δ
integration-tests 39.09% <0.00%> (-0.09%) ⬇️
python-3.10 57.29% <100.00%> (+0.30%) ⬆️
python-3.11 57.31% <100.00%> (+0.31%) ⬆️
python-3.12 57.29% <100.00%> (+0.30%) ⬆️
python-3.13 57.31% <100.00%> (+0.31%) ⬆️
python-3.14 57.31% <100.00%> (+0.31%) ⬆️
python-filler-3.12 23.70% <0.00%> (-0.01%) ⬇️

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 78.72% <100.00%> (+27.81%) ⬆️

... and 2 files with indirect coverage changes

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

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 3 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread infrahub_sdk/ctl/generator.py Outdated

@ogenstad ogenstad left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For a change like this we also need to ensure that we have the same behavior within Infrahub itself. I.e. when a generator runs within Infrahub. Does this already work as expected when the generator runs inside Infrahub or was this validated?

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 27, 2026

Copy link
Copy Markdown

Deploying infrahub-sdk-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: 3a69f22
Status: ✅  Deploy successful!
Preview URL: https://c0e7c87b.infrahub-sdk-python.pages.dev
Branch Preview URL: https://issue-1289.infrahub-sdk-python.pages.dev

View logs

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 3 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread infrahub_sdk/ctl/generator.py Outdated
@pthmas

pthmas commented Aug 27, 2026

Copy link
Copy Markdown
Author

@ogenstad the server never had this bug: it resolves each target’s variables with member.extract(params=...) and never touches a name attribute. Comparing the two did show a drift: the CLI hardcoded {"name": ...} as the tracking-group key and only used the first parameter, so for {rule_id: rule_id__value} a CLI run and a server run landed in different tracking groups. Reworked the PR to use extract() in the CLI too. Should be same behavior on both paths now.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 3 files (changes from recent commits).

Requires human review: Auto-approval blocked because this review re-detected 1 unresolved issue already reported by Cubic.
Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread tests/unit/ctl/test_generator.py Outdated
`infrahubctl generator` built the per-target params from a hardcoded `name`
attribute and aborted with "The node doesn't have an attribute for name"
whenever the target group held members of a kind without one. It also read the
query variables from the first parameter key rather than from the declared
attribute path.

Resolve the whole parameters mapping with `extract()`, the same call Infrahub
makes when it runs a generator, so target kinds without a name work, every
declared parameter reaches the query, and a CLI run shares its tracking group
with a server run.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type/bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: infrahubctl generator fails on target nodes that have no name attribute

2 participants