Skip to content
Closed
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
16 changes: 10 additions & 6 deletions src/datajoint/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,19 @@ def __init__(
password: str,
port: int | None = None,
use_tls: bool | dict | None = None,
*,
backend: str | None = None,
config_override: "Config | None" = None,
) -> None:
# Config reference - use override if provided, else global config
self._config = config_override if config_override is not None else config

if ":" in host:
# the port in the hostname overrides the port argument
host, port = host.split(":")
port = int(port)
elif port is None:
port = config["database.port"]
port = self._config["database.port"]
self.conn_info = dict(host=host, port=port, user=user, passwd=password)
if use_tls is not False:
# use_tls can be: None (auto-detect), True (enable), False (disable), or dict (custom config)
Expand All @@ -186,11 +192,9 @@ def __init__(
self._query_cache = None
self._is_closed = True # Mark as closed until connect() succeeds

# Config reference - defaults to global config, but Instance sets its own
self._config = config

# Select adapter based on configured backend
backend = self._config["database.backend"]
# Select adapter: explicit backend > config backend
if backend is None:
backend = self._config["database.backend"]
self.adapter = get_adapter(backend)

self.connect()
Expand Down
15 changes: 10 additions & 5 deletions src/datajoint/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,16 @@ def __init__(
if port is None:
port = self.config.database.port

# Create connection
self.connection = Connection(host, user, password, port, use_tls)

# Attach config to connection so tables can access it
self.connection._config = self.config
# Create connection with this instance's config and backend
self.connection = Connection(
host,
user,
password,
port,
use_tls,
backend=self.config.database.backend,
config_override=self.config,
)

def Schema(
self,
Expand Down