This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new a9084509d6d airflow-ctl: fix variable import to correctly handle falsy
values (#64362)
a9084509d6d is described below
commit a9084509d6db322a26e5478673309b369b68e85a
Author: Henry Chen <[email protected]>
AuthorDate: Mon Mar 30 11:14:58 2026 +0800
airflow-ctl: fix variable import to correctly handle falsy values (#64362)
---
.../airflowctl/ctl/commands/variable_command.py | 2 +-
.../ctl/commands/test_variable_command.py | 31 ++++++++++++++++++++++
2 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/airflow-ctl/src/airflowctl/ctl/commands/variable_command.py
b/airflow-ctl/src/airflowctl/ctl/commands/variable_command.py
index 466be2ccac7..88bf33a0f01 100644
--- a/airflow-ctl/src/airflowctl/ctl/commands/variable_command.py
+++ b/airflow-ctl/src/airflowctl/ctl/commands/variable_command.py
@@ -51,7 +51,7 @@ def import_(args, api_client=NEW_API_CLIENT) -> list[str]:
vars_to_update = []
for k, v in var_json.items():
value, description = v, None
- if isinstance(v, dict) and v.get("value"):
+ if isinstance(v, dict) and "value" in v:
value, description = v["value"], v.get("description")
vars_to_update.append(
diff --git
a/airflow-ctl/tests/airflow_ctl/ctl/commands/test_variable_command.py
b/airflow-ctl/tests/airflow_ctl/ctl/commands/test_variable_command.py
index 9703c8f866b..a0598d03459 100644
--- a/airflow-ctl/tests/airflow_ctl/ctl/commands/test_variable_command.py
+++ b/airflow-ctl/tests/airflow_ctl/ctl/commands/test_variable_command.py
@@ -83,6 +83,37 @@ class TestCliVariableCommands:
)
assert response == [self.key]
+ @pytest.mark.parametrize(
+ "falsy_value",
+ [
+ "",
+ 0,
+ False,
+ ],
+ ids=["empty_string", "zero", "false"],
+ )
+ def test_import_falsy_values(self, api_client_maker, tmp_path,
monkeypatch, falsy_value):
+ """Test that falsy values (empty string, 0, False) are correctly
imported."""
+ api_client = api_client_maker(
+ path="/api/v2/variables",
+ response_json=self.bulk_response_success.model_dump(),
+ expected_http_status_code=200,
+ kind=ClientKind.CLI,
+ )
+
+ monkeypatch.chdir(tmp_path)
+ expected_json_path = tmp_path / self.export_file_name
+ variable_file = {
+ self.key: {"value": falsy_value, "description": "test falsy
value"},
+ }
+
+ expected_json_path.write_text(json.dumps(variable_file))
+ response = variable_command.import_(
+ self.parser.parse_args(["variables", "import",
expected_json_path.as_posix()]),
+ api_client=api_client,
+ )
+ assert response == [self.key]
+
def test_import_error(self, api_client_maker, tmp_path, monkeypatch):
api_client = api_client_maker(
path="/api/v2/variables",