boushphong opened a new issue, #35872:
URL: https://github.com/apache/airflow/issues/35872
### Apache Airflow version
2.7.3
### What happened
We have a Secret backend that retrieves connection uri. We encountered an
error where if we have a connection uri that has multiple hosts (like a MongoDB
sharded cluster uri). The host and port parts will be extracted incorrectly and
cause an error:
```
File
"/Users/buiducphong/Projects/vinitus-airflow-core/venv/lib/python3.10/site-packages/sqlalchemy/orm/state.py",
line 481, in _initialize_instance
with util.safe_reraise():
File
"/Users/buiducphong/Projects/vinitus-airflow-core/venv/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py",
line 70, in __exit__
compat.raise_(
File
"/Users/buiducphong/Projects/vinitus-airflow-core/venv/lib/python3.10/site-packages/sqlalchemy/util/compat.py",
line 211, in raise_
raise exception
File
"/Users/buiducphong/Projects/vinitus-airflow-core/venv/lib/python3.10/site-packages/sqlalchemy/orm/state.py",
line 479, in _initialize_instance
return manager.original_init(*mixed[1:], **kwargs)
File
"/Users/buiducphong/Projects/vinitus-airflow-core/venv/lib/python3.10/site-packages/airflow/models/connection.py",
line 127, in __init__
self._parse_from_uri(uri)
File
"/Users/buiducphong/Projects/vinitus-airflow-core/venv/lib/python3.10/site-packages/airflow/models/connection.py",
line 199, in _parse_from_uri
self.port = uri_parts.port
File
"/opt/homebrew/Cellar/[email protected]/3.10.13/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/parse.py",
line 185, in port
raise ValueError(f"Port could not be cast to integer value as {port!r}")
ValueError: Port could not be cast to integer value as
'20019,dummyhost2:20019'
```
The full connection uri is
`mongodb://dummy_user:dummy_password@dummyhost1:20019,dummyhost2:20019/`,
however when Airflow Connection evaluates the string, it will extract
`dummyhost1` as the host and `20019,dummyhost2:20019` as the port which would
lead to a `ValueError`
### What you think should happen instead
Airflow Connection should be able handle the case where the host consists of
multiple hosts by default.
### How to reproduce
Run this code:
```python3
from airflow.models import Connection
conn = Connection(
conn_id="dummy_connection",
uri="mongodb://dummy_user:dummy_password@dummyhost1:20019,dummyhost2:20019/"
)
```
### Operating System
Ubuntu
### Versions of Apache Airflow Providers
_No response_
### Deployment
Other
### Deployment details
_No response_
### Anything else
_No response_
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
--
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]