From 477194194d1fc7f5fc9b979a86945c2b5773199a Mon Sep 17 00:00:00 2001 From: Phillip Cloud <417981+cpcloud@users.noreply.github.com> Date: Fri, 21 Jun 2024 08:21:28 -0400 Subject: [PATCH 1/2] test(mysql): add test for mysql port usage in `_from_url` --- ibis/backends/mysql/tests/test_client.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ibis/backends/mysql/tests/test_client.py b/ibis/backends/mysql/tests/test_client.py index 1c0d8784adef..f7877f462e46 100644 --- a/ibis/backends/mysql/tests/test_client.py +++ b/ibis/backends/mysql/tests/test_client.py @@ -12,6 +12,13 @@ import ibis import ibis.expr.datatypes as dt from ibis import udf +from ibis.backends.mysql.tests.conftest import ( + IBIS_TEST_MYSQL_DB, + MYSQL_HOST, + MYSQL_PASS, + MYSQL_USER, +) +from ibis.backends.tests.errors import MySQLOperationalError from ibis.util import gen_name MYSQL_TYPES = [ @@ -234,3 +241,10 @@ def test_list_tables_schema_warning_refactor(con): assert mysql_tables.issubset(con.list_tables(database="mysql")) assert mysql_tables.issubset(con.list_tables(database=("mysql",))) + + +def test_invalid_port(): + port = 4000 + url = f"mysql://{MYSQL_USER}:{MYSQL_PASS}@{MYSQL_HOST}:{port}/{IBIS_TEST_MYSQL_DB}" + with pytest.raises(MySQLOperationalError): + ibis.connect(url) From 055cd17105980c987df1657d543a24c35a45d9e6 Mon Sep 17 00:00:00 2001 From: Phillip Cloud <417981+cpcloud@users.noreply.github.com> Date: Fri, 21 Jun 2024 08:22:00 -0400 Subject: [PATCH 2/2] fix(mysql): ensure that `port` is captured in MySQL `_from_url` implementation --- ibis/backends/mysql/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ibis/backends/mysql/__init__.py b/ibis/backends/mysql/__init__.py index dd9ef3056d58..467fa9b7155e 100644 --- a/ibis/backends/mysql/__init__.py +++ b/ibis/backends/mysql/__init__.py @@ -66,6 +66,7 @@ def _from_url(self, url: str, **kwargs): "password": url.password or "", "host": url.hostname, "database": database or "", + "port": url.port or None, } for name, value in query_params.items(): @@ -91,6 +92,9 @@ def _from_url(self, url: str, **kwargs): if "password" in kwargs and kwargs["password"] is None: del kwargs["password"] + if "port" in kwargs and kwargs["port"] is None: + del kwargs["port"] + return self.connect(**kwargs) @cached_property