Skip to content

Report missing required airflowctl options as readable errors - #75177

Merged
shahar1 merged 1 commit into
apache:mainfrom
Rishabh00b:airflowctl-friendly-required-arg-errors
Oct 30, 2026
Merged

shahar1 merged 1 commit into
apache:mainfrom
Rishabh00b:airflowctl-friendly-required-arg-errors

Conversation

@Rishabh00b

Copy link
Copy Markdown
Contributor

Running a generated airflowctl command without a field the API requires (for example airflowctl connections create --connection-id foo) currently crashes with a raw pydantic ValidationError traceback ending in Input should be a valid string ... input_value=None.

This catches that error when the request body is built, uses FieldInfo.is_required() to separate missing required fields from invalid values, and exits with the following arguments are required: --conn-type. Invalid values are reported against their flag. No request is sent in either case.

Related: #57721, parent #57633.

Note: #74554 is already open for #57721. I opened this before noticing it. I'm happy to close this if the maintainers prefer that PR, or to rebase and fold in anything useful.

Testing: 5 new tests in test_cli_config.py (fail without the change, pass with it). ruff check, ruff format --check and mypy pass. The full airflow-ctl suite gives 445 passed and 1 failed; the failure (test_import_rejects_non_object_json) also occurs on main because my sandbox has no keyring backend. I did not run prek or Breeze.

Was generative AI tooling used to co-author this PR?

  • Yes (Claude Code, Claude Sonnet 5.5)

Generated-by: Claude Code (Claude Sonnet 5.5) following the guidelines

🤖 Generated with Claude Code

https://claude.ai/code/session_01PLWtW8cKWizvRLaFPf8BQD

When a generated airflowctl command such as `connections create` is run
without a datamodel field that the API requires, the unset option reaches
pydantic as None and the CLI crashes with a raw ValidationError traceback
("Input should be a valid string ... input_value=None").

Catch the ValidationError when the request body is built, use pydantic's
FieldInfo.is_required() to tell missing required fields from invalid values,
and exit with a message naming the flags, e.g.
"the following arguments are required: --conn-type". Invalid values are
reported against their flag. No request is sent in either case.

Part of apache#57633, addresses apache#57721.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01PLWtW8cKWizvRLaFPf8BQD
@shahar1

shahar1 commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Undrafted as I'd like to include this in the airflowctl 0.1.6 release :)
I'll review when CI finishes running

@shahar1 shahar1 left a comment

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.

Small, contained fix: catching ValidationError where the request body is built turns a raw pydantic traceback into an argparse-style "the following arguments are required: --conn-type" message, keeps every existing flag and positional unchanged, and the tests cover missing, optional, invalid and end-to-end paths (all five pass locally against current main; CI on 87fb51d is green, including airflow-ctl:P3.11 tests and Static checks).

Smaller observations

  • See inline comments on airflow-ctl/tests/airflow_ctl/ctl/test_cli_config.py:999.

This review was drafted by an AI-assisted tool and
confirmed by an Apache Airflow maintainer. The maintainer
approving this PR has read the findings and signed off. If
something feels off, please reply on the PR and a maintainer
will follow up.

More on how Apache Airflow handles maintainer review:
Contributing guide.

@shahar1
shahar1 merged commit fbc18bc into apache:main Oct 30, 2026
115 of 126 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

Backport successfully created: airflow-ctl/v0-1-test

Note: As of Merging PRs targeted for Airflow 3.X
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.

In matter of doubt please ask in #release-management Slack channel.

Status Branch Result
✅ airflow-ctl/v0-1-test PR Link

shahar1 pushed a commit that referenced this pull request Oct 30, 2026
… readable errors (#75177) (#76089)

When a generated airflowctl command such as `connections create` is run
without a datamodel field that the API requires, the unset option reaches
pydantic as None and the CLI crashes with a raw ValidationError traceback
("Input should be a valid string ... input_value=None").

Catch the ValidationError when the request body is built, use pydantic's
FieldInfo.is_required() to tell missing required fields from invalid values,
and exit with a message naming the flags, e.g.
"the following arguments are required: --conn-type". Invalid values are
reported against their flag. No request is sent in either case.

Part of #57633, addresses #57721.
(cherry picked from commit fbc18bc)

Co-authored-by: Rishabh <[email protected]>
shahar1 added a commit that referenced this pull request Oct 31, 2026
#69317 made required request-body fields required in argparse, and
#75177 added a test expecting the post-parse validation to report a
missing --conn-type. Each passed on its own, but together argparse
rejects the command during parsing, so the test failed on main. The
argparse error is the intended behaviour; the test now checks it.
shahar1 added a commit to shahar1/airflow that referenced this pull request Oct 31, 2026
…he#76092)

apache#69317 made required request-body fields required in argparse, and
apache#75177 added a test expecting the post-parse validation to report a
missing --conn-type. Each passed on its own, but together argparse
rejects the command during parsing, so the test failed on main. The
argparse error is the intended behaviour; the test now checks it.

(cherry picked from commit 9c164b5)
shahar1 added a commit that referenced this pull request Oct 31, 2026
…dation error (#69317) (#76116)

* [airflow-ctl/v0-1-test] Fix airflowctl operations create command validation error (#69317)

The only conflict was context: _find_subgroup_suffix from the operation subgroups change is not on this branch and stays out. The fix itself applies unchanged.

(cherry picked from commit 1c3b3de)

Co-authored-by: Pratiksha Badheka <[email protected]>

* Fix airflowctl required-option test broken by concurrent merges (#76092)

#69317 made required request-body fields required in argparse, and
#75177 added a test expecting the post-parse validation to report a
missing --conn-type. Each passed on its own, but together argparse
rejects the command during parsing, so the test failed on main. The
argparse error is the intended behaviour; the test now checks it.

(cherry picked from commit 9c164b5)

---------

Co-authored-by: Pratiksha Badheka <[email protected]>
shahar1 added a commit to shahar1/airflow that referenced this pull request Oct 31, 2026
A connection entry without conn_type, or with a bad value such as a
non-numeric port, made the import fail with a raw pydantic dump. The
dump did not say which connection in the file was broken, and a missing
conn_type showed up as "Input should be a valid string", not as a
missing field. Generated commands got readable messages in apache#75177; the
hand-built import path did not.
shahar1 added a commit that referenced this pull request Oct 31, 2026
…76090)

A connection entry without conn_type, or with a bad value such as a
non-numeric port, made the import fail with a raw pydantic dump. The
dump did not say which connection in the file was broken, and a missing
conn_type showed up as "Input should be a valid string", not as a
missing field. Generated commands got readable messages in #75177; the
hand-built import path did not.
shahar1 added a commit that referenced this pull request Oct 31, 2026
…tl connections import (#76090) (#76141)

A connection entry without conn_type, or with a bad value such as a
non-numeric port, made the import fail with a raw pydantic dump. The
dump did not say which connection in the file was broken, and a missing
conn_type showed up as "Input should be a valid string", not as a
missing field. Generated commands got readable messages in #75177; the
hand-built import path did not.
(cherry picked from commit 2e8f6f9)

Co-authored-by: Shahar Epstein <[email protected]>
@Rishabh00b
Rishabh00b deleted the airflowctl-friendly-required-arg-errors branch November 1, 2026 14:28
shahar1 pushed a commit that referenced this pull request Nov 19, 2026
… readable errors (#75177) (#76089)

When a generated airflowctl command such as `connections create` is run
without a datamodel field that the API requires, the unset option reaches
pydantic as None and the CLI crashes with a raw ValidationError traceback
("Input should be a valid string ... input_value=None").

Catch the ValidationError when the request body is built, use pydantic's
FieldInfo.is_required() to tell missing required fields from invalid values,
and exit with a message naming the flags, e.g.
"the following arguments are required: --conn-type". Invalid values are
reported against their flag. No request is sent in either case.

Part of #57633, addresses #57721.
(cherry picked from commit fbc18bc)

Co-authored-by: Rishabh <[email protected]>
shahar1 added a commit that referenced this pull request Nov 19, 2026
…dation error (#69317) (#76116)

* [airflow-ctl/v0-1-test] Fix airflowctl operations create command validation error (#69317)

The only conflict was context: _find_subgroup_suffix from the operation subgroups change is not on this branch and stays out. The fix itself applies unchanged.

(cherry picked from commit 1c3b3de)

Co-authored-by: Pratiksha Badheka <[email protected]>

* Fix airflowctl required-option test broken by concurrent merges (#76092)

#69317 made required request-body fields required in argparse, and
#75177 added a test expecting the post-parse validation to report a
missing --conn-type. Each passed on its own, but together argparse
rejects the command during parsing, so the test failed on main. The
argparse error is the intended behaviour; the test now checks it.

(cherry picked from commit 9c164b5)

---------

Co-authored-by: Pratiksha Badheka <[email protected]>
shahar1 added a commit that referenced this pull request Nov 19, 2026
…tl connections import (#76090) (#76141)

A connection entry without conn_type, or with a bad value such as a
non-numeric port, made the import fail with a raw pydantic dump. The
dump did not say which connection in the file was broken, and a missing
conn_type showed up as "Input should be a valid string", not as a
missing field. Generated commands got readable messages in #75177; the
hand-built import path did not.
(cherry picked from commit 2e8f6f9)

Co-authored-by: Shahar Epstein <[email protected]>
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