Revanth14 commented on code in PR #68700:
URL: https://github.com/apache/airflow/pull/68700#discussion_r3439317176
##########
airflow-core/src/airflow/models/connection.py:
##########
@@ -219,6 +222,32 @@ def _validate_extra(extra, conn_id) -> None:
raise ValueError(f"Encountered non-JSON in `extra` field for
connection {conn_id!r}.")
return None
+ @staticmethod
+ def _coerce_port(port: int | str | None) -> int | None:
+ if port is None:
+ return None
+ if isinstance(port, bool):
+ raise ValueError(f"Expected integer value for `port`, but got
{port!r} instead.")
+ if isinstance(port, int):
+ return port
+ if isinstance(port, str):
+ try:
+ return int(port)
+ except ValueError:
+ raise ValueError(f"Expected integer value for `port`, but got
{port!r} instead.") from None
Review Comment:
The `str` case is reachable through direct construction
(`Connection(port="5432")`) and `from_json`. `from_json` historically coerced
string ports, so I kept that compatibility. It is not for the URI path, since
`urlsplit(...).port` is already an `int`.
Tests cover this: `"1"` / `"65535"` are accepted and normalized, while `"0"`
/ `"65536"` / non-integer strings are rejected after coercion.
I also switched this helper to `match` / `case` in the follow-up change.
--
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]