haroldfabla2-hue opened a new pull request, #68863: URL: https://github.com/apache/airflow/pull/68863
## Summary This PR adds validation to ensure that the `port` field in Airflow connections is a valid TCP/UDP port number (0-65535). Previously, users could create connections with invalid port values like -1, 99999999, or any other integer outside the valid range, and Airflow would accept and persist them without complaint. ## Changes - Added `_validate_port()` function in `airflow.models.connection` to validate port range (0-65535) - Added validation in `Connection.__init__()` for individual connection creation - Added validation in `Connection._parse_from_uri()` for URI-based connection creation - Added `_validate_port()` static method in `airflow.sdk.definitions.connection` for Task SDK - Added validation in `Connection.__init__()` for Task SDK connection creation - Added validation in `Connection.from_uri()` for Task SDK URI-based connection creation - Added Pydantic `field_validator` in `api_fastapi/execution_api/datamodels.connection.ConnectionResponse` for REST API ## Affected Areas - Core connection model (`airflow.models.connection`) - Task SDK connection definition (`airflow.sdk.definitions.connection`) - Public REST API connection request schema (`api_fastapi/execution_api/datamodels/connection.py`) - Execution API connection schema (handled by Pydantic) ## Why Fix This Port numbers have a well-defined valid range by the TCP/IP specification (0-65535). Accepting values outside this range produces connections that can never work, with no feedback to the user at the point of creation. Validation should be enforced at the boundary, not discovered at runtime inside a hook or provider. ## Test Plan - Try creating a connection with port = -1 (should fail) - Try creating a connection with port = 99999999 (should fail) - Try creating a connection with port = 8080 (should succeed) - Try creating a connection with port = 0 (should succeed - reserved port) - Try creating a connection via URI with invalid port (should fail) ## Checklist - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [x] I have commented my code, particularly in hard-to-understand areas - [x] I have made corresponding changes to the documentation Closes #68382 -- 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]
