fix: record generator changes against the account that ran the generator
Why
Infrahub records the changes made by a generator against the task worker's account, not the account that ran the generator (#11480).
Closes #11480
Depends on opsmill/infrahub-sdk-python#1504.
What changed
The caller's account was lost in two places:
flowchart LR
M["mutation"] --> R["generator-run flow<br>(1) dropped the context"] --> G["SDK generator<br>(2) client copy dropped it"]
run_generatornow declarescontext: EventContextand applies it to its client. It is anEventContextbecause the action path sends one.- The
python_sdkpointer moves to the SDK fix:clone()keeps the request context, so the generator's copy of the client keeps the caller's account.
Permissions do not change: the server still checks the worker's token and only records the caller's account.
How to review
- 540dfe8: test. An account runs the generator, and the generated tag and the generator instance must be recorded against it.
- 0d1ba04: fix.
test_execute_generator_actionnow passes a context, because the flow requires one. - 41caed8: submodule bump. To update to the merge commit once the SDK pull request is merged.
- a74861e: changelog fragment.
Not checked: the account used when Infrahub runs the generator after a merge.
How to test
uv run pytest backend/tests/functional/generator/
Also tested on a live instance (Docker stack built from this branch, with the car-dealership test repository). The generated tag, the generator instance and the tracking group are recorded against the account that ran the generator when:
- an account runs the generator with
CoreGeneratorDefinitionRun, with or withoutwait_until_completion - an admin runs it with
context.accountset to another account - a
CoreGeneratorActionruns it after an account updates a target
The infrahub.node.created and infrahub.node.updated events carry the same account. On a stack built from stable, all of these record the worker's account (admin).
In a proposed change, the generated tag on the branch is recorded against the account that created the proposed change, on stable as with this change.
Checklist
- Tests added/updated
- Changelog entry added (
uv run towncrier create ...) - External docs updated (if user-facing or ops-facing change)
- Internal .md docs updated (internal knowledge and AI code tools knowledge)
- I have reviewed AI generated content
š¤ Generated with Claude Code