Skip to content

Commit e1ad919

Browse files
fix: Enable SSL by default when use_tls not specified
When use_tls=None (auto-detect), now sets ssl=True which the MySQL adapter converts to ssl={} for PyMySQL, properly enabling SSL with default settings. Before: use_tls=None → ssl={} → might not enable SSL properly After: use_tls=None → ssl=True → converted to ssl={} → enables SSL The retry logic (lines 218-231) still allows fallback to non-SSL if the server doesn't support it (since ssl_input=None). Fixes test_secure_connection - SSL now enabled when connecting with default parameters.
1 parent efb8482 commit e1ad919

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/datajoint/adapters/mysql.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ def connect(
8888
init_command = kwargs.get("init_command")
8989
# Handle both ssl (old) and use_tls (new) parameter names
9090
ssl = kwargs.get("use_tls", kwargs.get("ssl"))
91+
# Convert boolean True to dict for PyMySQL (PyMySQL expects dict or SSLContext)
92+
if ssl is True:
93+
ssl = {} # Enable SSL with default settings
9194
charset = kwargs.get("charset", "")
9295

9396
return client.connect(

src/datajoint/connection.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,15 @@ def __init__(
172172
port = config["database.port"]
173173
self.conn_info = dict(host=host, port=port, user=user, passwd=password)
174174
if use_tls is not False:
175-
self.conn_info["ssl"] = use_tls if isinstance(use_tls, dict) else {}
175+
# use_tls can be: None (auto-detect), True (enable), False (disable), or dict (custom config)
176+
if isinstance(use_tls, dict):
177+
self.conn_info["ssl"] = use_tls
178+
elif use_tls is None:
179+
# Auto-detect: try SSL, fallback to non-SSL if server doesn't support it
180+
self.conn_info["ssl"] = True
181+
else:
182+
# use_tls=True: enable SSL with default settings
183+
self.conn_info["ssl"] = True
176184
self.conn_info["ssl_input"] = use_tls
177185
self.init_fun = init_fun
178186
self._conn = None

0 commit comments

Comments
 (0)