Skip to content

Commit fe8293a

Browse files
committed
fix error in the API params to create a branch
1 parent 042a77f commit fe8293a

7 files changed

Lines changed: 12 additions & 21 deletions

File tree

src/tinybird_sdk/api/branches.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@
55
from typing import Any
66
from urllib.parse import urlencode
77

8+
from ..cli.config_types import BranchDataMode
89
from .fetcher import tinybird_fetch
910

10-
LAST_PARTITION = "last_partition"
11-
12-
LAST_PARTITION = "last_partition"
13-
1411

1512
@dataclass(frozen=True, slots=True)
1613
class BranchApiConfig:
@@ -28,7 +25,7 @@ class TinybirdBranch:
2825

2926
@dataclass(frozen=True, slots=True)
3027
class CreateBranchOptions:
31-
last_partition: bool = False
28+
branch_data_mode: BranchDataMode | None = None
3229

3330

3431
class BranchApiError(Exception):
@@ -79,8 +76,8 @@ def create_branch(
7976
) -> TinybirdBranch:
8077
normalized = config if isinstance(config, BranchApiConfig) else BranchApiConfig(**config)
8178
params = {"name": name}
82-
if options and options.last_partition:
83-
params["data"] = LAST_PARTITION
79+
if options and options.branch_data_mode:
80+
params["data"] = options.branch_data_mode
8481
url = f"{normalized.base_url.rstrip('/')}/v1/environments?{urlencode(params)}"
8582
response = tinybird_fetch(url, method="POST", headers=_headers(normalized.token))
8683

src/tinybird_sdk/cli/commands/build.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,7 @@ def run_build(options: BuildCommandOptions | dict[str, Any] | None = None) -> Bu
141141
branch_options = None
142142
branch_value = config.get("branch_data_mode")
143143
if branch_value and config.get("dev_mode") != "local":
144-
branch_options = CreateBranchOptions(
145-
last_partition=(branch_value == "last_partition"),
146-
)
144+
branch_options = CreateBranchOptions(branch_data_mode=branch_value)
147145
branch = get_or_create_branch(
148146
{"base_url": config["base_url"], "token": config["token"]},
149147
config["tinybird_branch"],

src/tinybird_sdk/cli/commands/clear.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def run_clear(options: ClearCommandOptions | dict[str, Any] | None = None) -> Cl
6363
branch_options = None
6464
branch_value = config.get("branch_data_mode")
6565
if branch_value and config.get("dev_mode") != "local":
66-
branch_options = CreateBranchOptions(last_partition=(branch_value == "last_partition"))
66+
branch_options = CreateBranchOptions(branch_data_mode=branch_value)
6767

6868
clear_branch(
6969
{"base_url": config["base_url"], "token": config["token"]},

src/tinybird_sdk/cli/commands/preview.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,7 @@ def run_preview(
154154
branch_options = None
155155
branch_value = config.get("branch_data_mode")
156156
if branch_value and config.get("dev_mode") != "local":
157-
branch_options = CreateBranchOptions(
158-
last_partition=(branch_value == "last_partition"),
159-
)
157+
branch_options = CreateBranchOptions(branch_data_mode=branch_value)
160158
branch = create_branch(
161159
{"base_url": config["base_url"], "token": config["token"]},
162160
preview_branch_name,

src/tinybird_sdk/client/base.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,7 @@ def _resolve_branch_context(self) -> ClientContext:
162162
branch_options = None
163163
branch_value = config.get("branch_data_mode")
164164
if branch_value and config.get("dev_mode") != "local":
165-
branch_options = CreateBranchOptions(
166-
last_partition=(branch_value == "last_partition")
167-
)
165+
branch_options = CreateBranchOptions(branch_data_mode=branch_value)
168166

169167
branch = get_or_create_branch(
170168
{

tests/test_api_branches_options.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def fake_fetch(url: str, **_kwargs: Any) -> _FakeResponse:
4040
create_branch(
4141
{"base_url": "https://api.tinybird.co", "token": "p.test"},
4242
"x",
43-
options=CreateBranchOptions(last_partition=True),
43+
options=CreateBranchOptions(branch_data_mode="last_partition"),
4444
)
4545

4646
parsed = urlparse(called_urls[0])
@@ -89,9 +89,9 @@ def fake_create_branch(
8989
clear_branch(
9090
{"base_url": "https://api.tinybird.co", "token": "p.test"},
9191
"x",
92-
options=CreateBranchOptions(last_partition=True),
92+
options=CreateBranchOptions(branch_data_mode="last_partition"),
9393
)
9494

9595
assert len(captured_options) == 1
9696
assert captured_options[0] is not None
97-
assert captured_options[0].last_partition is True
97+
assert captured_options[0].branch_data_mode == "last_partition"

tests/test_client_parity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def fake_get_or_create_branch(*_args: Any, **kwargs: Any) -> dict[str, Any]:
7676
assert context["token"] == "branch_token"
7777
assert context["is_branch_token"] is True
7878
assert context["branch_name"] == "feature_alpha"
79-
assert captured["options"].last_partition is True
79+
assert captured["options"].branch_data_mode == "last_partition"
8080

8181

8282
def test_tokens_namespace_wraps_token_api_errors(monkeypatch: pytest.MonkeyPatch) -> None:

0 commit comments

Comments
 (0)