Repository navigation
fix: use configured default_branch in generators, transforms, checks - #1293
Conversation
…hecks `InfrahubOperation.branch_name` and `InfrahubCheck.branch_name` resolved the branch from the local Git checkout whenever no explicit branch was passed, ignoring the client's resolved default branch. Runs against a configured `default_branch` therefore failed with `BranchNotFoundError` when the local Git branch did not exist in Infrahub. Resolve the branch from `client.default_branch` instead, which already honours the `default_branch_from_git` config flag, so the Git branch is only used when that flag is enabled.
Deploying infrahub-sdk-python with
|
| Latest commit: |
f7499ae
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://70f9ab83.infrahub-sdk-python.pages.dev |
| Branch Preview URL: | https://issue-1290.infrahub-sdk-python.pages.dev |
There was a problem hiding this comment.
All reported issues were addressed across 5 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## stable #1293 +/- ##
==========================================
+ Coverage 84.24% 85.06% +0.82%
==========================================
Files 147 148 +1
Lines 13066 13282 +216
Branches 1940 1950 +10
==========================================
+ Hits 11007 11298 +291
+ Misses 1494 1421 -73
+ Partials 565 563 -2
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 11 files with indirect coverage changes 🚀 New features to boost your workflow:
|
`ConfigBase.default_infrahub_branch` always resolved the local Git branch from the process working directory. Operations and checks are rooted at their own `root_directory`, so with `default_branch_from_git` enabled they could resolve against a different repository than the one they run in. Add `ConfigBase.get_default_infrahub_branch(directory=...)`, which the existing property now delegates to, and pass `root_directory` from `InfrahubOperation` and `InfrahubCheck`. Stub the Git lookup in the branch resolution tests. They previously compared against `get_branch()` evaluated at assert time, which depends on the state of the local checkout and fails outright when it has no active branch, as in CI.
There was a problem hiding this comment.
All reported issues were addressed across 5 files (changes from recent commits).
Requires human review: Auto-approval blocked because this review re-detected 1 unresolved issue already reported by Cubic.
Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 7 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
INFP-739] opsmill/infrahub-sdk-python#1414 adds cost_level and cost_estimate to the CoreGraphQLQuery protocols, so `invoke backend.validate-generated` finds the SDK protocols up to date. The commit is on top of the SDK stable branch, which also brings dependency bumps and the fix that makes generators, transforms and checks use the configured default branch (opsmill/infrahub-sdk-python#1293). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Why
Running
infrahubctl generator,transformorcheckwithout--branchtargeted thelocal Git checkout's active branch instead of the configured
default_branch, failing withBranchNotFoundErrorwhenever that Git branch did not exist in Infrahub. The fallback thedefault_branch_from_gitflag exists to gate was applied unconditionally, overriding anexplicitly configured
INFRAHUB_DEFAULT_BRANCH.Goal: with
default_branch_from_gitunset orfalse, an operation with no explicit branchtargets the configured
default_branch— the same branch the rest of the command already uses.Non-goals:
Config.clonedrops an explicitbranchargument whendefault_branch_from_gitis enabled. Pre-existing, out of scope here, will be filed separately.
Closes #1290
What changed
Behavioral changes:
default_branch.default_branch_from_gitis enabled.infrahubctl generatoris no longer internally inconsistent: the GraphQL query and theschema fetch resolve to the same branch.
Implementation notes:
InfrahubOperation.__init__resolves the branch once asbranch or client.default_branch.client.default_branchis already the output ofConfigBase.default_infrahub_branch, whichmakes the
default_branch_from_gitdecision — so the flag stays honoured in exactly one placerather than being reimplemented. Same pattern already used in
ctl/cli_commands.py:386.branch_namebecomes a plain accessor; theGitRepoManagerlookup and theself.gitattribute are removed from
operation.py.InfrahubCheck.branch_namegets the same treatment. Its client is optional, so with no client(no config to consult) it falls back to the existing
get_branch()helper.InfrahubGeneratorandInfrahubTransformbothinherit from
InfrahubOperation, as does every library consumer.What stayed the same:
branch_nameandroot_directoryare unchanged.default_branch_from_git=truebehaviour is unchanged.How to review
Start with
infrahub_sdk/operation.py— the whole fix isself.branch = branch or client.default_branch.infrahub_sdk/checks.pyis the same change with an extra no-client arm.How to test
Regression coverage: explicit branch wins / no branch + flag off → configured
default_branch/no branch + flag on → local Git branch. Both new
default_branchassertions fail on thepre-fix code.
Impact & rollout
without setting
default_branch_from_git=truenow gets the configureddefault_branch(default
main) instead of their checkout branch. That is the documented contract; noted inthe changelog entry.
INFRAHUB_DEFAULT_BRANCHandINFRAHUB_DEFAULT_BRANCH_FROM_GITnow behave as documented.
Checklist
changelog/1290.fixed.md)Summary by cubic
Fixes generators, transforms, and checks to target the configured
default_branchwhen no explicit branch is passed, eliminating theBranchNotFoundErrorthat occurred when the local Git branch didn't exist in Infrahub.default_branch_from_gitis enabled, and is resolved from the operation'sroot_directoryinstead of the process working directory.infrahubctl generatornow resolves the same branch for its GraphQL query and schema fetch.default_branch_from_gitnow target the configureddefault_branch(defaultmain) instead of the checkout branch. No config or env changes required. Closes bug: generator and transform runs ignore default_branch and take the local git branch instead #1290.Written for commit f7499ae. Summary will update on new commits.