Repository navigation
Validate connection ports in core model - #74461
Conversation
3b20222 to
ab0c501
Compare
fat-catTW
left a comment
There was a problem hiding this comment.
Thanks for the PR.
I think this needs one more change because the stricter core validation regresses the existing CLI path.
--conn-port is currently parsed as a string, and connections_add() passes args.conn_port directly into Connection(...). With this PR, Connection(port="9083") now raises ValueError, so the existing airflow connections add ... --conn-port=9083 path breaks.
I confirmed this with the existing CLI test:
airflow-core/tests/unit/cli/commands/test_connection_command.py::TestCliAddConnections::test_cli_connection_add[individual-parts]
It fails with:
ValueError: Expected integer value for port, but got '9083' instead.
Could you coerce/validate the CLI value before constructing Connection? For example, parse ARG_CONN_PORT as int, or otherwise reuse the same port coercion logic before passing it to the model.
|
Correction: fixed in commit abd1b2c. The --conn-port CLI argument is now parsed as an integer before constructing Connection, so the existing airflow connections add ... --conn-port=9083 path no longer passes a string into the stricter core validation. |
Rejecting them would break callers that pass the port as a string (env vars, config values, custom secrets backends); from_json already converts them. Generated-by: Claude Opus 5
potiuk
left a comment
There was a problem hiding this comment.
Thanks. I pushed a small fixup on top: @validates("port") now converts string ports the same way from_json does (via _coerce_port), so Connection(port="5432") and assignments like conn.port = "5432" keep working for callers that read the port from env vars, config or a custom secrets backend. Out-of-range values and non-numeric strings are still rejected. The tests now cover the accepted strings ("123", "0", "") next to the rejected ones ("abc", "65536"). With that, this stays a validation improvement rather than an API break, so no newsfragment is needed. Will merge once CI is green.
Drafted-by: Claude Code (Opus 5.5); reviewed by @potiuk before posting
|
Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions. |
Part of the split implementation for #68382.\n\nAdds range and type validation for Connection.port at the core model boundary, including JSON and assignment coverage. This PR intentionally contains only the core model and its tests; it does not close the issue by itself.