Skip to content

fix(client): keep the request context when cloning a client - #1504

Merged
polmichel merged 6 commits into
stablefrom
fix/generator-keeps-request-context
Nov 12, 2026
Merged

polmichel merged 6 commits into
stablefrom
fix/generator-keeps-request-context

Conversation

@polmichel

@polmichel polmichel commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Why

InfrahubClient.clone() returns a client without the original client's request_context. Generators, transforms and checks work with a clone of the client they receive, so the changes they save are sent without the caller's account, and Infrahub records them against the worker's account (opsmill/infrahub#11480).

What changed

flowchart LR
	C["client<br>request_context = caller"] -->|"clone()"| K["clone<br>request_context = caller"]
Loading

clone() now copies the request_context, on the async and sync clients. In both repositories, the only caller outside tests is InfrahubOperation, the base class of generators, transforms and checks.

Used by opsmill/infrahub#11504.

How to review

  1. 9df7c36 and c321fa7: tests.
  2. 7ad158d: fix, and the regenerated clone() reference.
  3. 4502535: changelog fragment.

How to test

uv run pytest tests/unit/sdk/test_client.py -k clone tests/unit/sdk/test_generator.py
  • test_clone_keeps_request_context: the clone has the same request_context.
  • test_generator_writes_carry_the_client_request_context: a mutation sent by a generator carries the caller's account.

Both fail without the fix. Also tested end to end on a live Infrahub instance through opsmill/infrahub#11504. The 3 unit tests that fail in tests/unit/ctl also fail on stable.

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)

🤖 Generated with Claude Code

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Deploying infrahub-sdk-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: 92f9d7e
Status: ✅  Deploy successful!
Preview URL: https://51c8d264.infrahub-sdk-python.pages.dev
Branch Preview URL: https://fix-generator-keeps-request.infrahub-sdk-python.pages.dev

View logs

@polmichel polmichel added the type/bug Something isn't working as expected label Nov 9, 2026
@codecov

codecov Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

@@            Coverage Diff             @@
##           stable    #1504      +/-   ##
==========================================
+ Coverage   87.85%   87.88%   +0.03%     
==========================================
  Files         157      157              
  Lines       15656    15660       +4     
  Branches     2114     2114              
==========================================
+ Hits        13754    13763       +9     
+ Misses       1341     1336       -5     
  Partials      561      561              
Flag Coverage Δ
integration-tests 42.95% <50.00%> (+<0.01%) ⬆️
python-3.10 63.05% <100.00%> (+0.13%) ⬆️
python-3.11 63.03% <100.00%> (+0.12%) ⬆️
python-3.12 63.03% <100.00%> (+0.12%) ⬆️
python-3.13 63.03% <100.00%> (+0.12%) ⬆️
python-3.14 63.04% <100.00%> (+0.12%) ⬆️
python-3.15 63.05% <100.00%> (+0.13%) ⬆️
python-filler-3.12 23.03% <50.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/client.py 86.19% <100.00%> (+0.04%) ⬆️

... and 1 file with indirect coverage changes

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

@polmichel polmichel changed the title fix(generator): keep the client's request context in generators, transforms and checks fix(client): keep the request context when cloning a client Nov 9, 2026
Ubuntu and others added 4 commits November 9, 2026 22:02
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…st context

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@polmichel
polmichel force-pushed the fix/generator-keeps-request-context branch from a093843 to 4502535 Compare November 9, 2026 22:03
@github-actions github-actions Bot added the type/documentation Improvements or additions to documentation label Nov 9, 2026
@polmichel polmichel self-assigned this Nov 9, 2026
@polmichel
polmichel marked this pull request as ready for review November 9, 2026 22:34
@polmichel
polmichel requested a review from a team as a code owner November 9, 2026 22:34

@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 5 files

Tip: Get a Slack DM when cubic finishes reviewing your PRs. Connect Slack

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread infrahub_sdk/client.py Resolved
Changing the account or priority of a cloned client no longer changes
the request context of the client it was cloned from.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…erforms

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@polmichel
polmichel force-pushed the fix/generator-keeps-request-context branch from 0e10dd7 to 92f9d7e Compare November 10, 2026 08:47
@polmichel
polmichel merged commit daf2fa0 into stable Nov 12, 2026
32 checks passed
@polmichel
polmichel deleted the fix/generator-keeps-request-context branch November 12, 2026 17:57
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 type/documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants