Eason09053360 opened a new pull request, #73098:
URL: https://github.com/apache/airflow/pull/73098
## Why
`airflowctl connections test --connection-id <id> --conn-type <type>` is
rejected for any
connection that has a stored host or port:
```
Client error message: {'detail': 'The host or port to test differs from the
stored connection.
Include the credentials to test in the request body.'}
```
The endpoint fills the fields the caller leaves out from the stored
connection, and works out
which fields the caller meant to override from the keys present in the body
— `model_fields_set`
(`routes/public/connections.py:387`, `services/public/connections.py:47`). A
key whose value is
`null` still counts as present.
The generated CLI builds `ConnectionBody` from a dict holding every field
(`cli_config.py:858`), so argparse's `None` for each flag the user did not
pass goes out as an
explicit `null`. The server reads that as "clear these fields": the stored
host reads as changed,
no credentials were supplied, and the request is refused. On a connection
with no host it is not
refused, but the stored login, password and extra are overwritten with
`None` and a blank
connection is tested instead.
`ConnectionsOperations.create` already passes `exclude_none=True` for this
reason, as do pools,
backfills and asset events; `test` was missed. `exclude_unset=True` would be
a no-op, since the
command factory always populates every field. Nothing in the CLI can express
an intentional
`null`, so dropping them loses no caller intent.
## What
`ConnectionsOperations.test` now passes `exclude_none=True`.
`test_test_uses_schema_alias_in_request_body` asserted the full body
*including* the seven nulls,
pinning the broken behaviour; it now expects the three keys actually set,
matching
`test_create_uses_schema_alias_in_request_body`. Reverting the one-line fix
fails it. The added
comment records why the exact body matters beyond the alias, so the
assertion is not loosened
back into the bug.
Left alone to keep this to one behaviour change: `update` has the same root
cause and is already
covered by #71333. `bulk` has it too, but `exclude_none=True` would only
half-fix it — the
`connections`/`variables`/`pools import` commands also pass hard-coded
fallbacks such as
`description=v.get("description", "")`, which are not `None` and would still
overwrite stored
values under `--action-on-existing-key overwrite`. Fixing that means having
those three commands
send only the keys present in the file.
---
##### Was generative AI tooling used to co-author this PR?
- [ ] No
--
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]