fix: record generator changes against the account that ran the generator

Merged
PO
8d ago
+59-4

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"]
  1. run_generator now declares context: EventContext and applies it to its client. It is an EventContext because the action path sends one.
  2. The python_sdk pointer 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

  1. 540dfe8: test. An account runs the generator, and the generated tag and the generator instance must be recorded against it.
  2. 0d1ba04: fix. test_execute_generator_action now passes a context, because the flow requires one.
  3. 41caed8: submodule bump. To update to the merge commit once the SDK pull request is merged.
  4. 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 without wait_until_completion
  • an admin runs it with context.account set to another account
  • a CoreGeneratorAction runs 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