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.
Component
Python SDK
Infrahub SDK version
1.23.1 (verified on
develop@ 9b39ab4)Current Behavior
rebase()andvalidate()on both branch managers declare aBranchDatareturn type but return the mutation'sokboolean.infrahub_sdk/branch.py, sync manager:The async manager (
:119,:129) has the same mismatch.merge()is correct — declared-> bool, returnsok.Consequence: a caller who trusts the annotation writes
result.nameorresult.statusand getsAttributeError: 'bool' object has no attribute ...at runtime. A type checker will not flag it, because it believes the declaration.Note that
validate()requestsquery_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:
-> bool— the smaller, non-breaking fix that matches what the methods do and whatmerge()already declares; orBranchDataby requestingMUTATION_QUERY_DATA(ascreate()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 (BranchRebasehasobject = Field(BranchType)and the resolver re-reads the branch after the workflow), so returningBranchDatathere is achievable if wanted.Steps to Reproduce
Run mypy over that snippet: no error is reported, because
rebase()is declared to returnBranchData.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.infrahubAnsible collection does not yet expose. Related collection issue: opsmill/infrahub-ansible#395.