Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(mysql): ensure that port is captured in MySQL _from_url implementation #9421

Merged
merged 2 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading