Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Allow description to be passed in when using variables CLI #34791

Merged
merged 19 commits into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
c428fc5
Feature: Allow description to be passed in when uring variables CLI
Zhenye-Na Oct 5, 2023
9b98b2a
Feature: Allow description to be passed in when uring variables CLI
Zhenye-Na Oct 5, 2023
9e43737
fix CLI unit tests
Zhenye-Na Oct 8, 2023
377d2af
Remove short option for description argument and update unit tests
Zhenye-Na Oct 13, 2023
b004060
Feature: Allow description to be passed in when uring variables CLI
Zhenye-Na Oct 5, 2023
35f75ed
Feature: Allow description to be passed in when uring variables CLI
Zhenye-Na Oct 5, 2023
9f3aedd
fix CLI unit tests
Zhenye-Na Oct 8, 2023
2697be8
Remove short option for description argument and update unit tests
Zhenye-Na Oct 13, 2023
977699a
Merge branches '34756' and '34756' of https://github.com/Zhenye-Na/ai…
Zhenye-Na Oct 15, 2023
5f9526a
Feature: Allow description to be passed in when uring variables CLI
Zhenye-Na Oct 5, 2023
f1164e4
Feature: Allow description to be passed in when uring variables CLI
Zhenye-Na Oct 5, 2023
8c5c6df
fix CLI unit tests
Zhenye-Na Oct 8, 2023
15f764c
Remove short option for description argument and update unit tests
Zhenye-Na Oct 13, 2023
b68e92d
Merge branches '34756' and '34756' of https://github.com/Zhenye-Na/ai…
Zhenye-Na Oct 20, 2023
c86449c
Add assertion to check variables' description as well
Zhenye-Na Oct 20, 2023
5425039
Merge branch 'main' into 34756
Zhenye-Na Oct 20, 2023
e62bbe4
Update tests/cli/commands/test_variable_command.py
Zhenye-Na Oct 23, 2023
fd73509
Merge branch 'main' into 34756
Zhenye-Na Oct 23, 2023
7beb851
Merge branch 'main' into 34756
eladkal Oct 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion airflow/cli/cli_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,12 @@ def string_lower_type(val):
ARG_DEFAULT = Arg(
("-d", "--default"), metavar="VAL", default=None, help="Default value returned if variable does not exist"
)
ARG_VAR_DESCRIPTION = Arg(
("--description",),
default=None,
required=False,
help="Variable description, optional when setting a variable",
)
ARG_DESERIALIZE_JSON = Arg(("-j", "--json"), help="Deserialize JSON variable", action="store_true")
ARG_SERIALIZE_JSON = Arg(("-j", "--json"), help="Serialize JSON variable", action="store_true")
ARG_VAR_IMPORT = Arg(("file",), help="Import variables from JSON file")
Expand Down Expand Up @@ -1442,7 +1448,7 @@ class GroupCommand(NamedTuple):
name="set",
help="Set variable",
func=lazy_load_command("airflow.cli.commands.variable_command.variables_set"),
args=(ARG_VAR, ARG_VAR_VALUE, ARG_SERIALIZE_JSON, ARG_VERBOSE),
args=(ARG_VAR, ARG_VAR_VALUE, ARG_VAR_DESCRIPTION, ARG_SERIALIZE_JSON, ARG_VERBOSE),
),
ActionCommand(
name="delete",
Expand Down
4 changes: 2 additions & 2 deletions airflow/cli/commands/variable_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ def variables_get(args):
@cli_utils.action_cli
@providers_configuration_loaded
def variables_set(args):
"""Create new variable with a given name and value."""
Variable.set(args.key, args.value, serialize_json=args.json)
"""Create new variable with a given name, value and description."""
Variable.set(args.key, args.value, args.description, serialize_json=args.json)
print(f"Variable {args.key} created")


Expand Down
9 changes: 9 additions & 0 deletions tests/cli/commands/test_variable_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ def test_variables_set(self):
with pytest.raises(KeyError):
Variable.get("foo1")

def test_variables_set_with_description(self):
"""Test variable_set command with optional description argument"""
variable_command.variables_set(
self.parser.parse_args(["variables", "set", "foo", "bar", "--description", "foo_bar_description"])
)
assert Variable.get("foo") is not None
uranusjr marked this conversation as resolved.
Show resolved Hide resolved
with pytest.raises(KeyError):
Variable.get("foo1")

def test_variables_get(self):
Variable.set("foo", {"foo": "bar"}, serialize_json=True)

Expand Down