Skip to content

Commit

Permalink
fix(mysql): ensure that port is captured in MySQL _from_url imple…
Browse files Browse the repository at this point in the history
…mentation (#9421)

Fixes #9417.
  • Loading branch information
cpcloud authored Jun 21, 2024
1 parent 1839c13 commit 5bb4971
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ibis/backends/mysql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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
Expand Down
14 changes: 14 additions & 0 deletions ibis/backends/mysql/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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)

0 comments on commit 5bb4971

Please sign in to comment.