Skip to content

Report missing required API fields in airflowctl CLI - #73317

Closed
Clara0619 wants to merge 2 commits into
apache:mainfrom
Clara0619:fix-required-field-error
Closed

Clara0619 wants to merge 2 commits into
apache:mainfrom
Clara0619:fix-required-field-error

Conversation

@Clara0619

Copy link
Copy Markdown

Summary

Fixes #57721.

This change improves how airflowctl handles 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 create now reports missing required arguments such as:

  • --dag-id
  • --from-date
  • --to-date

before request-model validation occurs.

The existing CLI-default behavior is preserved, including fields such as logical_date that are supplied by airflowctl itself.

Tests

Added regression tests covering:

  • all required BackfillPostBody fields missing
  • each required field missing individually
  • successful parsing when all required fields are provided
  • optional boolean/default fields remaining optional
  • CLI-supplied defaults such as logical_date remaining optional

Relevant tests passed locally, and git diff --check completed 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.

@boring-cyborg

boring-cyborg Bot commented Sep 18, 2026

Copy link
Copy Markdown

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
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our prek-hooks will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example Dag that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: [email protected]
    Slack: https://s.apache.org/airflow-slack

@Clara0619
Clara0619 marked this pull request as ready for review September 20, 2026 02:46
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,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Suggested change
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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the required-field check to exclude nullable fields as suggested. The full airflow-ctl test suite passes locally (400 passed). Thanks!

@kaxil

kaxil commented Oct 1, 2026

Copy link
Copy Markdown
Member

Closing this. It makes required body fields required=True flags, the design from #68000. On #68014, potiuk noted the two designs are mutually exclusive and that the positional approach is the right one, matching the dev-list consensus cli_config.py already follows for required primitive params.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve the error message when a required field from the API is not provided

3 participants