-
Notifications
You must be signed in to change notification settings - Fork 17.4k
Add task instance management commands to airflowctl CLI #67947
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
base: main
Are you sure you want to change the base?
Changes from all commits
bfbbdcf
7b381ab
57c0055
cdf6803
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,8 @@ | |
| import inspect | ||
| import os | ||
| import sys | ||
| import types as builtin_types | ||
| import typing | ||
| from argparse import Namespace | ||
| from collections.abc import Callable, Iterable | ||
| from enum import Enum | ||
|
|
@@ -52,6 +54,22 @@ | |
| BUILD_DOCS = "BUILDING_AIRFLOW_DOCS" in os.environ | ||
|
|
||
|
|
||
| def _is_list_annotation(annotation: Any) -> bool: | ||
| """Check whether a Pydantic field annotation is a list type (including Optional[list[...]]).""" | ||
| origin = typing.get_origin(annotation) | ||
| if origin is list: | ||
| return True | ||
| # Handle both typing.Union (Optional[list[...]]) and PEP-604 X | Y (types.UnionType) | ||
| if origin is typing.Union or isinstance(annotation, builtin_types.UnionType): | ||
| return any(_is_list_annotation(arg) for arg in typing.get_args(annotation) if arg is not type(None)) | ||
| return False | ||
|
|
||
|
|
||
| def _get_bool_flag_default(field_info: Any) -> bool: | ||
| """Return the CLI default for a generated bool flag: the datamodel field's default (the API default), or False.""" | ||
| return field_info.default if isinstance(field_info.default, bool) else False | ||
|
Comment on lines
+68
to
+70
|
||
|
|
||
|
|
||
| def lazy_load_command(import_path: str) -> Callable: | ||
| """Create a lazy loader for command.""" | ||
| _, _, name = import_path.rpartition(".") | ||
|
|
@@ -399,7 +417,17 @@ def __init__(self, file_path: str | Path | None = None): | |
| # Exclude parameters that are not needed for CLI from datamodels | ||
| self.excluded_parameters = ["schema_"] | ||
| # This list is used to determine if the command/operation needs to output data | ||
| self.output_command_list = ["list", "get", "create", "delete", "update", "trigger", "add", "edit"] | ||
| self.output_command_list = [ | ||
| "list", | ||
| "get", | ||
| "create", | ||
| "delete", | ||
| "update", | ||
| "trigger", | ||
| "add", | ||
| "edit", | ||
| "clear", | ||
| ] | ||
| self.exclude_operation_names = ["LoginOperations", "VersionOperations", "BaseOperations"] | ||
| self.exclude_method_names = [ | ||
| "error", | ||
|
|
@@ -411,6 +439,8 @@ def __init__(self, file_path: str | Path | None = None): | |
| ] | ||
| self.excluded_output_keys = [ | ||
| "total_entries", | ||
| "next_cursor", | ||
| "previous_cursor", | ||
| ] | ||
|
|
||
| def _inspect_operations(self) -> None: | ||
|
|
@@ -587,7 +617,9 @@ def _create_arg_for_non_primitive_type( | |
| arg_type=self._python_type_from_string(field_type.annotation), | ||
| arg_action=argparse.BooleanOptionalAction if field_type.annotation is bool else None, # type: ignore | ||
| arg_help=f"{field} for {parameter_key} operation", | ||
| arg_default=False if field_type.annotation is bool else None, | ||
| arg_default=_get_bool_flag_default(field_type) | ||
| if field_type.annotation is bool | ||
| else None, | ||
| ) | ||
| ) | ||
| else: | ||
|
|
@@ -602,7 +634,7 @@ def _create_arg_for_non_primitive_type( | |
| arg_type=self._python_type_from_string(annotation), | ||
| arg_action=argparse.BooleanOptionalAction if annotation is bool else None, # type: ignore | ||
| arg_help=f"{field} for {parameter_key} operation", | ||
| arg_default=False if annotation is bool else None, | ||
| arg_default=_get_bool_flag_default(field_type) if annotation is bool else None, | ||
| ) | ||
| ) | ||
| return commands | ||
|
|
@@ -717,10 +749,19 @@ def _get_func(args: Namespace, api_operation: dict, api_client: Client = NEW_API | |
| datamodel_param_name = parameter_key | ||
| if expanded_parameter in self.excluded_parameters: | ||
| continue | ||
| if expanded_parameter in args_dict.keys(): | ||
| if ( | ||
| expanded_parameter in args_dict.keys() | ||
| and args_dict[expanded_parameter] is not None | ||
| ): | ||
| val = args_dict[expanded_parameter] | ||
|
Comment on lines
+752
to
+756
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I understand correctly, the
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, you're right on both counts. Fixed by changing the default from False to None for bool fields in Added a regression test ( |
||
| if isinstance(val, str) and expanded_parameter in datamodel.model_fields: | ||
| if _is_list_annotation( | ||
| datamodel.model_fields[expanded_parameter].annotation | ||
| ): | ||
| val = [v.strip() for v in val.split(",") if v.strip()] | ||
| method_params[parameter_key][ | ||
| self._sanitize_method_param_key(expanded_parameter) | ||
| ] = args_dict[expanded_parameter] | ||
| ] = val | ||
|
|
||
| if datamodel: | ||
| if datamodel_param_name: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.