Repository navigation
Report missing required airflowctl options as readable errors - #75177
Conversation
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
|
Undrafted as I'd like to include this in the airflowctl 0.1.6 release :) |
shahar1
left a comment
There was a problem hiding this comment.
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.
Backport successfully created: airflow-ctl/v0-1-testNote: As of Merging PRs targeted for Airflow 3.X In matter of doubt please ask in #release-management Slack channel.
|
… 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]>
#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.
…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)
…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]>
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.
…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.
…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]>
… 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]>
…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]>
…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]>
Running a generated airflowctl command without a field the API requires (for example
airflowctl connections create --connection-id foo) currently crashes with a raw pydanticValidationErrortraceback ending inInput 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 withthe 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 --checkandmypypass. The fullairflow-ctlsuite gives 445 passed and 1 failed; the failure (test_import_rejects_non_object_json) also occurs onmainbecause my sandbox has no keyring backend. I did not runprekor Breeze.Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Claude Sonnet 5.5) following the guidelines
🤖 Generated with Claude Code
https://claude.ai/code/session_01PLWtW8cKWizvRLaFPf8BQD