@@ -41,23 +41,31 @@ schema = dj.Schema("my_schema", connection=conn)
4141
4242### conn.config
4343
44- Every connection has a ` config ` attribute that:
45- - Copies from global ` dj.config ` at connection time
46- - Is always mutable (even in thread-safe mode)
47- - Provides connection-scoped settings
44+ Every connection has a ` config ` attribute for uniform access:
45+
46+ | Connection source | ` conn.config ` |
47+ | -------------------| ---------------|
48+ | ` dj.conn() ` | ** Is** ` dj.config ` (same object) |
49+ | ` dj.Connection(...) ` | ** Copy** of ` dj.config ` (independent) |
50+
51+ This ensures all internal code can use ` self.connection.config ` uniformly.
4852
4953``` python
50- conn.config.safemode # Read setting
51- conn.config.safemode = False # Write setting (always allowed)
52- conn.config.stores = {... } # Configure stores for this connection
54+ # Global connection - config is dj.config
55+ conn = dj.conn()
56+ conn.config.safemode = False # Modifies dj.config
57+
58+ # Explicit connection - config is independent copy
59+ conn = dj.Connection(host = " localhost" , user = " u" , password = " p" )
60+ conn.config.safemode = False # Only affects this connection
5361```
5462
5563## Connection Flow: Schema → Tables
5664
5765### How connections propagate
5866
5967```
60- Connection
68+ Connection (has .config)
6169 ↓
6270Schema (stores connection)
6371 ↓
@@ -89,6 +97,17 @@ class Mouse(dj.Manual):
8997# Mouse().connection returns Mouse._connection (from schema)
9098```
9199
100+ ### Uniform config access
101+
102+ All internal code uses ` self.connection.config ` :
103+
104+ ``` python
105+ # Works the same whether connection is from dj.conn() or dj.Connection()
106+ self .connection.config.safemode
107+ self .connection.config.display.limit
108+ self .connection.config.stores
109+ ```
110+
92111### In thread_safe=True mode
93112
94113``` python
@@ -110,9 +129,10 @@ Mouse().insert(...) # Uses schema.connection.config for settings
110129| ` dj.config ` read | Works | Works |
111130| ` dj.config ` write | Works | Raises ` ThreadSafetyError ` |
112131| ` dj.conn() ` | Works | Raises ` ThreadSafetyError ` |
132+ | ` dj.conn().config ` | Is ` dj.config ` | N/A |
113133| ` dj.Schema("name") ` | Works (uses ` conn() ` ) | Raises ` ThreadSafetyError ` |
114134| ` dj.Connection(...) ` | Works | Works |
115- | ` conn.config ` read/write | Works | Works |
135+ | ` conn.config ` | Copy of ` dj.config ` | Copy of ` dj.config ` |
116136| ` Schema(..., connection=conn) ` | Works | Works |
117137| Table operations | Use ` conn.config ` | Use ` conn.config ` |
118138
@@ -132,9 +152,9 @@ Mouse().insert(...) # Uses schema.connection.config for settings
132152- ` dj.conn() ` : Raise ` ThreadSafetyError ` when ` thread_safe=True `
133153- ` Schema.__init__ ` : Raise ` ThreadSafetyError ` when ` connection=None ` and ` thread_safe=True `
134154
135- ### 3. Add conn.config
136- - ` Connection.__init__ ` : Create ` self .config` as copy of global ` dj.config `
137- - ` conn.config ` is always mutable
155+ ### 3. Add conn.config to all connections
156+ - ` dj.conn() ` : Set ` conn .config = dj.config` (same object for backward compatibility)
157+ - ` dj.Connection(...) ` : Set ` self.config = copy(dj.config) ` (independent copy)
138158
139159### 4. Refactor internal code to use conn.config
140160
0 commit comments