Repository navigation
Conversation
|
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide
|
| 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_required=field_type.is_required() and cli_defaults[field] is None, |
There was a problem hiding this comment.
Thanks for the patch! LGTM Overall
Just one nit:
In Pydantic, "required" means the key must be present. It doesn't mean the value can't be None. argparse already sets an omitted option to None, so a field that is required but nullable is satisfied without the flag. argparse only has to enforce fields that are required and not nullable:
| arg_required=field_type.is_required() and cli_defaults[field] is None, | |
| arg_required=field_type.is_required() and type(None) not in get_args(field_type.annotation), |
This follows the same rule as primitive parameters a few lines below
There was a problem hiding this comment.
Updated the required-field check to exclude nullable fields as suggested. The full airflow-ctl test suite passes locally (400 passed). Thanks!
Summary
Fixes #57721.
This change improves how
airflowctlhandles required fields from Pydantic API request models.Previously, required fields inside request-body models were exposed as CLI options but were not marked as required in
argparse. As a result, missing fields could reach Pydantic validation before the user received an error.This change propagates Pydantic's
is_required()information to the generated CLI arguments so missing required fields are reported directly by the CLI.For example,
backfills createnow reports missing required arguments such as:--dag-id--from-date--to-datebefore request-model validation occurs.
The existing CLI-default behavior is preserved, including fields such as
logical_datethat are supplied byairflowctlitself.Tests
Added regression tests covering:
BackfillPostBodyfields missinglogical_dateremaining optionalRelevant tests passed locally, and
git diff --checkcompleted successfully.Gen-AI disclosure
Gen-AI was used to assist with implementation and test drafting. I reviewed the changes and validated the final behavior and tests.