Skip to content

bug: branch rebase() and validate() are annotated -> BranchData but return a bool #1308

Description

@BeArchiTek

Component

Python SDK

Infrahub SDK version

1.23.1 (verified on develop @ 9b39ab4)

Current Behavior

rebase() and validate() on both branch managers declare a BranchData return type but return the mutation's ok boolean.

infrahub_sdk/branch.py, sync manager:

def rebase(self, branch_name: str) -> BranchData:
    ...
    response = self.client.execute_graphql(query=query.render(), tracker="mutation-branch-rebase")
    return response["BranchRebase"]["ok"]

def validate(self, branch_name: str) -> BranchData:
    ...
    response = self.client.execute_graphql(query=query.render(), tracker="mutation-branch-validate")
    return response["BranchValidate"]["ok"]

The async manager (:119, :129) has the same mismatch. merge() is correct — declared -> bool, returns ok.

Consequence: a caller who trusts the annotation writes result.name or result.status and gets AttributeError: 'bool' object has no attribute ... at runtime. A type checker will not flag it, because it believes the declaration.

Note that validate() requests query_data = {"ok": None} only, so there is no branch data in the response to return even if the annotation were to be honoured.

Expected Behavior

Either:

  • Correct the annotations to -> bool — the smaller, non-breaking fix that matches what the methods do and what merge() already declares; or
  • Return real BranchData by requesting MUTATION_QUERY_DATA (as create() does), if the branch object is considered useful to callers.

The first is the safe change. The second is a behaviour change for anyone already treating the result as truthy/falsy.

For rebase() specifically, note the server does return the rebased branch (BranchRebase has object = Field(BranchType) and the resolver re-reads the branch after the workflow), so returning BranchData there is achievable if wanted.

Steps to Reproduce

client = InfrahubClientSync(address="http://localhost:8000")
result = client.branch.rebase(branch_name="my-branch")
print(type(result))        # <class 'bool'>
print(result.name)         # AttributeError

Run mypy over that snippet: no error is reported, because rebase() is declared to return BranchData.

Additional Information

Prior art for treating a wrong annotation as a bug: #260 (wrong typing in RelationshipManager(Sync).remove).

Found while auditing which SDK capabilities the opsmill.infrahub Ansible collection does not yet expose. Related collection issue: opsmill/infrahub-ansible#395.

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/lowThis issue should be completed in a couple of hoursstate/need-triageThis issue needs to be triagedtype/bugSomething isn't working as expected

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions