jason810496 commented on code in PR #48706:
URL: https://github.com/apache/airflow/pull/48706#discussion_r2026145582
##########
providers/mysql/tests/unit/mysql/hooks/test_mysql.py:
##########
@@ -93,6 +93,35 @@ def test_get_uri(self, mock_connect):
args, kwargs = mock_connect.call_args
assert self.db_hook.get_uri() ==
"mysql://login:password@host/schema?charset=utf-8"
+ self.connection.login = "user@domain"
+ self.connection.password = "pass/word!"
+ assert self.db_hook.get_uri() ==
"mysql://user%40domain:pass%2Fword%21@host/schema?charset=utf-8"
+
+ # Test with mysql-connector-python client
+ self.connection.login = "user@domain"
+ self.connection.password = "password"
+ self.connection.extra = json.dumps({"client":
"mysql-connector-python"})
+ assert self.db_hook.get_uri() ==
"mysql+mysqlconnector://user%40domain:password@host/schema"
+
+ self.connection.port = 3307
+ assert self.db_hook.get_uri() ==
"mysql+mysqlconnector://user%40domain:password@host:3307/schema"
+
+ self.connection.schema = "db/name"
+ assert self.db_hook.get_uri() ==
"mysql+mysqlconnector://user%40domain:password@host:3307/db%2Fname"
+
+ self.connection.schema = "schema"
+ self.connection.extra = json.dumps(
+ {
+ "client": "mysql-connector-python",
+ "ssl_ca": "/path/to/ca",
+ "ssl_cert": "/path/to/cert with space",
+ }
+ )
+ assert (
+ self.db_hook.get_uri()
+ ==
"mysql+mysqlconnector://user%40domain:password@host:3307/schema?ssl_ca=%2Fpath%2Fto%2Fca&ssl_cert=%2Fpath%2Fto%2Fcert+with+space"
+ )
+
Review Comment:
How about refactoring the test cases using "pytest.parametrize"?
##########
providers/mysql/src/airflow/providers/mysql/hooks/mysql.py:
##########
@@ -363,3 +363,46 @@ def get_openlineage_database_dialect(self, _):
def get_openlineage_default_schema(self):
"""MySQL has no concept of schema."""
return None
+
+ def get_uri(self) -> str:
+ """Get URI for MySQL connection."""
+ from urllib.parse import quote_plus
Review Comment:
I think we could place the import at top level?
##########
providers/mysql/src/airflow/providers/mysql/hooks/mysql.py:
##########
@@ -363,3 +363,46 @@ def get_openlineage_database_dialect(self, _):
def get_openlineage_default_schema(self):
"""MySQL has no concept of schema."""
return None
+
+ def get_uri(self) -> str:
+ """Get URI for MySQL connection."""
+ from urllib.parse import quote_plus
+
+ conn = self.connection or self.get_connection(self.get_conn_id())
+ conn_schema = self.schema or conn.schema or ""
+ client_name = conn.extra_dejson.get("client", "mysqlclient")
+
+ # Determine URI prefix based on client
+ if client_name == "mysql-connector-python":
+ uri_prefix = "mysql+mysqlconnector://"
+ else: # default: mysqlclient
+ uri_prefix = "mysql://"
+
+ auth_part = ""
+ if conn.login is not None:
+ auth_part += quote_plus(conn.login)
+ if conn.password is not None:
Review Comment:
```suggestion
if conn.password:
```
##########
providers/mysql/src/airflow/providers/mysql/hooks/mysql.py:
##########
@@ -363,3 +363,46 @@ def get_openlineage_database_dialect(self, _):
def get_openlineage_default_schema(self):
"""MySQL has no concept of schema."""
return None
+
+ def get_uri(self) -> str:
+ """Get URI for MySQL connection."""
+ from urllib.parse import quote_plus
+
+ conn = self.connection or self.get_connection(self.get_conn_id())
+ conn_schema = self.schema or conn.schema or ""
+ client_name = conn.extra_dejson.get("client", "mysqlclient")
+
+ # Determine URI prefix based on client
+ if client_name == "mysql-connector-python":
+ uri_prefix = "mysql+mysqlconnector://"
+ else: # default: mysqlclient
+ uri_prefix = "mysql://"
+
+ auth_part = ""
+ if conn.login is not None:
Review Comment:
```suggestion
if conn.login:
```
--
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]