Skip to content

Commit a90411f

Browse files
fix: remove user input prompts from conn()
The low-level `conn()` function should not block execution waiting for user input. Instead, raise DataJointError if credentials are missing. Users should configure credentials via: - datajoint.config['database.user'] - datajoint.config['database.password'] - Or pass user= and password= arguments directly Closes #1343 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent a5ddd03 commit a90411f

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/datajoint/connection.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import re
1212
import warnings
1313
from contextlib import contextmanager
14-
from getpass import getpass
1514
from typing import Callable
1615

1716
import pymysql as client
@@ -110,9 +109,9 @@ def conn(
110109
host : str, optional
111110
Database hostname.
112111
user : str, optional
113-
MySQL username.
112+
Database username. Required if not set in config.
114113
password : str, optional
115-
MySQL password. Prompts if not provided.
114+
Database password. Required if not set in config.
116115
init_fun : callable, optional
117116
Initialization function called after connection.
118117
reset : bool, optional
@@ -125,15 +124,24 @@ def conn(
125124
-------
126125
Connection
127126
Persistent database connection.
127+
128+
Raises
129+
------
130+
DataJointError
131+
If user or password is not provided and not set in config.
128132
"""
129133
if not hasattr(conn, "connection") or reset:
130134
host = host if host is not None else config["database.host"]
131135
user = user if user is not None else config["database.user"]
132136
password = password if password is not None else config["database.password"]
133137
if user is None:
134-
user = input("Please enter DataJoint username: ")
138+
raise errors.DataJointError(
139+
"Database user not configured. Set datajoint.config['database.user'] or pass user= argument."
140+
)
135141
if password is None:
136-
password = getpass(prompt="Please enter DataJoint password: ")
142+
raise errors.DataJointError(
143+
"Database password not configured. Set datajoint.config['database.password'] or pass password= argument."
144+
)
137145
init_fun = init_fun if init_fun is not None else config["connection.init_function"]
138146
use_tls = use_tls if use_tls is not None else config["database.use_tls"]
139147
conn.connection = Connection(host, user, password, None, init_fun, use_tls)

0 commit comments

Comments
 (0)