Skip to content

fix(branch): add MERGING to BranchStatus enum (infrahub#9293)#1036

Merged
ogenstad merged 4 commits into
stablefrom
phill-20260519-add-merging-branchstatus-9293
May 20, 2026
Merged

fix(branch): add MERGING to BranchStatus enum (infrahub#9293)#1036
ogenstad merged 4 commits into
stablefrom
phill-20260519-add-merging-branchstatus-9293

Conversation

@PhillSimonds
Copy link
Copy Markdown
Contributor

@PhillSimonds PhillSimonds commented May 19, 2026

Summary

This patches the SDK side of the bug only — the server-side robustness improvements (guaranteeing a branch never stays in MERGING, or making BranchManager.all() tolerant of one malformed entry) are out of scope here and would land in opsmill/infrahub.

Reproduction (live, against Infrahub 1.9.5)

# Create a branch
curl -s -X POST http://localhost:8000/graphql/main -H "Authorization: Bearer $TOKEN" \
  -d '{"query":"mutation { BranchCreate(data: {name: \"repro-9293\", sync_with_git: false}) { ok object { id name status } } }"}'

# Strand it in MERGING
docker exec infrahub-database-1 cypher-shell -u neo4j -p admin \
  "MATCH (b:Branch {name: 'repro-9293'}) SET b.status = 'MERGING' RETURN b.status"

# Before this fix — inside the task worker:
docker exec infrahub-task-worker-1 python -c "
import asyncio
from infrahub_sdk import InfrahubClient, Config
asyncio.run(InfrahubClient(address='http://server:8000',
    config=Config(username='admin', password='infrahub')).branch.all())
"
# -> pydantic_core._pydantic_core.ValidationError: 1 validation error for BranchData
#    status
#      Input should be 'OPEN', 'NEED_REBASE', 'NEED_UPGRADE_REBASE', 'DELETING' or 'MERGED'
#      [type=enum, input_value='MERGING', input_type=str]

# After this fix:
# -> OK: client.branch.all() returned 2 branches
#      - main: status=OPEN
#      - repro-9293: status=MERGING

Test plan

  • pytest tests/unit/sdk/test_branch.py — 12 passed.
  • Live end-to-end repro against Infrahub 1.9.5 (infrahub-task-worker:1.9.5 image), patched in-container via docker cp, client.branch.all() now returns the MERGING branch.
  • Cross-enum coverage test will be added in opsmill/infrahub as part of the PR that bumps the SDK commit pin (per review feedback) — that side can iterate the actual server-side BranchStatus enum.

Follow-ups (separate PRs / not in this changeset)

  • opsmill/infrahub: bump python_sdk submodule pin once this is merged, target a 1.9.6 patch release; add the parametrized enum-coverage test there.
  • opsmill/infrahub: wrap _do_merge_branch body in try/finally so a worker death between the MERGING transition and MERGED/rollback can't permanently strand a branch.
  • opsmill/infrahub: optionally have BranchManager.all() skip+log malformed entries rather than failing the whole collection.

The server-side BranchStatus enum gained MERGING in Infrahub 1.9.3 (PR
opsmill/infrahub#9116) but the SDK enum was not updated. Any branch
returned with status="MERGING" — including a branch stranded in that
state by a task worker dying mid-merge — caused client.branch.all() to
raise ValidationError, which crashloops the task worker on every
sync_remote_repositories run.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@PhillSimonds PhillSimonds requested a review from a team as a code owner May 19, 2026 13:58
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented May 19, 2026

Deploying infrahub-sdk-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: a7a0a94
Status: ✅  Deploy successful!
Preview URL: https://8f51021b.infrahub-sdk-python.pages.dev
Branch Preview URL: https://phill-20260519-add-merging-b.infrahub-sdk-python.pages.dev

View logs

…string

ty rejects passing str where BranchStatus is annotated; switch to
BranchData.model_validate({...}) which mirrors how the SDK actually
parses server JSON in branch.py.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented May 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

@@           Coverage Diff           @@
##           stable    #1036   +/-   ##
=======================================
  Coverage   81.54%   81.54%           
=======================================
  Files         134      134           
  Lines       11467    11468    +1     
  Branches     1735     1735           
=======================================
+ Hits         9351     9352    +1     
  Misses       1569     1569           
  Partials      547      547           
Flag Coverage Δ
integration-tests 41.71% <0.00%> (-0.01%) ⬇️
python-3.10 54.56% <0.00%> (-0.03%) ⬇️
python-3.11 54.56% <0.00%> (-0.03%) ⬇️
python-3.12 54.58% <0.00%> (-0.01%) ⬇️
python-3.13 54.58% <0.00%> (-0.01%) ⬇️
python-3.14 54.56% <0.00%> (-0.01%) ⬇️
python-filler-3.12 22.67% <100.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/branch.py 68.75% <100.00%> (+0.21%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread tests/unit/sdk/test_branch.py Outdated
Comment thread changelog/1037.fixed.md Outdated
…orten note

- Drop test_branch_data_accepts_all_server_statuses: per review, the
  enum-coverage test belongs in the infrahub community repo where it
  can iterate over the actual server-side BranchStatus enum instead of
  a hardcoded list of strings. It will be added there as part of the
  PR that bumps the SDK commit pin.
- Rename changelog +branchstatus-merging.fixed.md → 1037.fixed.md to
  link it to the newly-filed SDK-side issue #1037 (migrated from
  opsmill/infrahub#9293).
- Shorten changelog note per review.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@ogenstad ogenstad merged commit e590b83 into stable May 20, 2026
21 checks passed
@ogenstad ogenstad deleted the phill-20260519-add-merging-branchstatus-9293 branch May 20, 2026 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: infrahub-task-worker crashloops with BranchData ValidationError when a branch is in MERGING status (SDK enum missing MERGING)

3 participants