You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "Clara0619 (via GitHub)" <gi...@apache.org> on 2026/09/18 09:51:35 UTC

[PR] Report missing required API fields in airflowctl CLI [airflow]

Clara0619 opened a new pull request, #73317:
URL: https://github.com/apache/airflow/pull/73317

   ## 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.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Report missing required API fields in airflowctl CLI [airflow]

Posted by "kaxil (via GitHub)" <gi...@apache.org>.
kaxil commented on PR #73317:
URL: https://github.com/apache/airflow/pull/73317#issuecomment-5940872266

   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.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Report missing required API fields in airflowctl CLI [airflow]

Posted by "Eason09053360 (via GitHub)" <gi...@apache.org>.
Eason09053360 commented on code in PR #73317:
URL: https://github.com/apache/airflow/pull/73317#discussion_r4091875206


##########
airflow-ctl/src/airflowctl/ctl/cli_config.py:
##########
@@ -730,6 +736,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_required=field_type.is_required() and cli_defaults[field] is None,

Review 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:
   
   ```suggestion
                       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



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Report missing required API fields in airflowctl CLI [airflow]

Posted by "Clara0619 (via GitHub)" <gi...@apache.org>.
Clara0619 commented on code in PR #73317:
URL: https://github.com/apache/airflow/pull/73317#discussion_r4118997017


##########
airflow-ctl/src/airflowctl/ctl/cli_config.py:
##########
@@ -730,6 +736,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_required=field_type.is_required() and cli_defaults[field] is None,

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



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Report missing required API fields in airflowctl CLI [airflow]

Posted by "boring-cyborg[bot] (via GitHub)" <gi...@apache.org>.
boring-cyborg[bot] commented on PR #73317:
URL: https://github.com/apache/airflow/pull/73317#issuecomment-5728318902

   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](https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
   Here are some useful points:
   - Pay attention to the quality of your code (ruff, mypy and type annotations). Our [prek-hooks]( https://github.com/apache/airflow/blob/main/contributing-docs/08_static_code_checks.rst#prerequisites-for-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](https://github.com/apache/airflow/blob/main/airflow-core/docs/howto/custom-operator.rst) Consider adding an example Dag that shows how users should use it.
   - Consider using [Breeze environment](https://github.com/apache/airflow/blob/main/dev/breeze/doc/README.rst) 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](https://www.apache.org/foundation/policies/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]( https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#coding-style-and-best-practices).
   - 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: dev@airflow.apache.org
   Slack: https://s.apache.org/airflow-slack
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Report missing required API fields in airflowctl CLI [airflow]

Posted by "kaxil (via GitHub)" <gi...@apache.org>.
kaxil closed pull request #73317: Report missing required API fields in airflowctl CLI
URL: https://github.com/apache/airflow/pull/73317


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org