shahar1 opened a new pull request, #76120: URL: https://github.com/apache/airflow/pull/76120
When an API server answers with a body that does not match the airflowctl datamodel (a newer server sending an enum value this client lacks, an HTML page from a URL that is not the API server, a request body rejected by a `*Body` model), the pydantic `ValidationError` escapes `safe_call_command` and the user gets a raw traceback. This makes every client/server version skew look like a crash and hides the actual problem. The handler now reports one line and exits 1, with three messages depending on the cause: - non-JSON body: `Server returned a non-JSON response for <Model>; check that the API URL points at the Airflow API server.` - request-body model (name ending in `Body`): `Input did not match the airflowctl model <Model> (invalid '<field>': <reason>).` - any other response model: `Response did not match the airflowctl model <Model> (invalid '<field>': <reason>). If the server is newer than this client, try upgrading airflowctl.` Pydantic's message is passed through `rich.markup.escape` so server-provided text cannot inject markup. On `main` the list path already re-raises the original `ValidationError` for non-JSON bodies (`validate_response`), so only the regression test for that path is added here. Tested with `uv run --project airflow-ctl pytest airflow-ctl/tests/airflow_ctl/ctl/test_cli_config.py airflow-ctl/tests/airflow_ctl/api/test_operations.py`: 336 passed, 1 failed. The failure, `test_create_command_without_required_option_exits_with_friendly_message`, fails on `main` without this change as well (argparse now reports `--conn-type` as required before the friendly-message path runs); it is unrelated and has a separate fix. Also being proposed for `airflow-ctl/v0-1-test` as part of the 0.1.6 compatibility work, where the same traceback shows up as soon as a 3.3+ or 3.4 server sends a value the 3.2-generated models do not know. --- ##### Was generative AI tooling used to co-author this PR? - [X] Yes — Claude Code (Fable 5.1) Generated-by: Claude Code (Fable 5.1) following [the guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions) -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
