Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/+e2f96e7b.removed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The previously deprecated 'background_execution' parameter under client.branch.create() was removed.
51 changes: 12 additions & 39 deletions infrahub_sdk/branch.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import warnings
from enum import Enum
from typing import TYPE_CHECKING, Any, Literal, overload
from urllib.parse import urlencode
Expand Down Expand Up @@ -93,7 +92,6 @@ async def create(
sync_with_git: bool = True,
description: str = "",
wait_until_completion: Literal[True] = True,
background_execution: bool | None = False,
) -> BranchData: ...

@overload
Expand All @@ -103,7 +101,6 @@ async def create(
sync_with_git: bool = True,
description: str = "",
wait_until_completion: Literal[False] = False,
background_execution: bool | None = False,
) -> str: ...

async def create(
Expand All @@ -112,35 +109,24 @@ async def create(
sync_with_git: bool = True,
description: str = "",
wait_until_completion: bool = True,
background_execution: bool | None = False,
) -> BranchData | str:
if background_execution is not None:
warnings.warn(
"`background_execution` is deprecated, please use `wait_until_completion` instead.",
DeprecationWarning,
stacklevel=1,
)

background_execution = background_execution or not wait_until_completion
input_data = {
# Should be switched to `wait_until_completion` once `background_execution` is removed server side.
"background_execution": background_execution,
"wait_until_completion": wait_until_completion,
"data": {
"name": branch_name,
"description": description,
"sync_with_git": sync_with_git,
},
}

mutation_query = MUTATION_QUERY_TASK if background_execution else MUTATION_QUERY_DATA
mutation_query = MUTATION_QUERY_DATA if wait_until_completion else MUTATION_QUERY_TASK
query = Mutation(mutation="BranchCreate", input_data=input_data, query=mutation_query)
response = await self.client.execute_graphql(query=query.render(), tracker="mutation-branch-create")

# Make sure server version is recent enough to support background execution, as previously
# using background_execution=True had no effect.
if background_execution and "task" in response["BranchCreate"]:
return response["BranchCreate"]["task"]["id"]
return BranchData(**response["BranchCreate"]["object"])
if wait_until_completion:
return BranchData(**response["BranchCreate"]["object"])

return response["BranchCreate"]["task"]["id"]

async def delete(self, branch_name: str) -> bool:
input_data = {
Expand Down Expand Up @@ -261,7 +247,6 @@ def create(
sync_with_git: bool = True,
description: str = "",
wait_until_completion: Literal[True] = True,
background_execution: bool | None = False,
) -> BranchData: ...

@overload
Expand All @@ -271,7 +256,6 @@ def create(
sync_with_git: bool = True,
description: str = "",
wait_until_completion: Literal[False] = False,
background_execution: bool | None = False,
) -> str: ...

def create(
Expand All @@ -280,35 +264,24 @@ def create(
sync_with_git: bool = True,
description: str = "",
wait_until_completion: bool = True,
background_execution: bool | None = False,
) -> BranchData | str:
if background_execution is not None:
warnings.warn(
"`background_execution` is deprecated, please use `wait_until_completion` instead.",
DeprecationWarning,
stacklevel=1,
)

background_execution = background_execution or not wait_until_completion
input_data = {
# Should be switched to `wait_until_completion` once `background_execution` is removed server side.
"background_execution": background_execution,
"wait_until_completion": wait_until_completion,
"data": {
"name": branch_name,
"description": description,
"sync_with_git": sync_with_git,
},
}

mutation_query = MUTATION_QUERY_TASK if background_execution else MUTATION_QUERY_DATA
mutation_query = MUTATION_QUERY_DATA if wait_until_completion else MUTATION_QUERY_TASK
query = Mutation(mutation="BranchCreate", input_data=input_data, query=mutation_query)
response = self.client.execute_graphql(query=query.render(), tracker="mutation-branch-create")

# Make sure server version is recent enough to support background execution, as previously
# using background_execution=True had no effect.
if background_execution and "task" in response["BranchCreate"]:
return response["BranchCreate"]["task"]["id"]
return BranchData(**response["BranchCreate"]["object"])
if wait_until_completion:
return BranchData(**response["BranchCreate"]["object"])

return response["BranchCreate"]["task"]["id"]

def delete(self, branch_name: str) -> bool:
input_data = {
Expand Down