Skip to content

Commit 697ec6d

Browse files
docs: conn.config uses same Config class, connection settings read-only
- Connection.from_config() creates a Config instance for conn.config - Database connection settings (host, port, user, password, use_tls, backend) become read-only after connection is established - Other settings remain mutable per-connection Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent c0598f4 commit 697ec6d

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

docs/design/thread-safe-mode.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,21 @@ schema = dj.Schema("my_schema", connection=conn)
4545
- `port`: Database port (default: 3306)
4646
- Any other setting from `dj.config` (e.g., `safemode`, `display_limit`, `stores`)
4747

48-
**Defaults:** Settings not explicitly provided use hardcoded defaults (same as `dj.config` defaults). Global `dj.config` is never accessed.
48+
**Config creation:** Uses the same `Config` class as global `dj.config`. Each connection gets its own `Config` instance via `conn.config`.
4949

50-
**Connection-scoped settings:** Stored on `conn.config` and accessed as `conn.config.safemode`, `conn.config.display_limit`, etc.
50+
**Read-only after connection:** Database connection settings become read-only after connection is established:
51+
- `host`, `port`, `user`, `password`, `use_tls`, `backend`
52+
53+
**Mutable settings:** All other settings remain mutable per-connection:
54+
- `safemode`, `display_limit`, `stores`, etc.
5155

5256
```python
5357
conn = dj.Connection.from_config(host="localhost", user="u", password="p")
5458
conn.config.safemode # True (default)
5559
conn.config.display_limit # 12 (default)
5660

57-
conn.config.safemode = False # Modify for this connection only
61+
conn.config.safemode = False # OK: modify for this connection
62+
conn.config.host = "other" # Error: read-only after connection
5863
```
5964

6065
## Behavior
@@ -69,9 +74,8 @@ conn.config.safemode = False # Modify for this connection only
6974

7075
## Read-Only Settings
7176

72-
Only `thread_safe` is read-only after initialization. It can only be set via:
73-
- Environment variable `DJ_THREAD_SAFE`
74-
- Config file `datajoint.json`
77+
- `thread_safe`: Read-only after global config initialization (set via env var or config file only)
78+
- `host`, `port`, `user`, `password`, `use_tls`, `backend`: Read-only on `conn.config` after connection is established
7579

7680
## Implementation
7781

@@ -82,8 +86,8 @@ Only `thread_safe` is read-only after initialization. It can only be set via:
8286
5. Add guard to `Schema.__init__` when `connection=None`
8387
6. Add `Connection.from_config()` class method that:
8488
- Accepts all connection params and settings as kwargs
85-
- Uses hardcoded defaults (never accesses global config)
86-
- Creates `conn.config` object to store connection-scoped settings
89+
- Creates a new `Config` instance for `conn.config`
90+
- Marks connection settings as read-only after connection
8791
7. Add `ThreadSafetyError` exception
8892

8993
## Exceptions

0 commit comments

Comments
 (0)