@@ -34,7 +34,7 @@ conn = dj.Connection(
3434
3535# Modify settings per-connection
3636conn.config.safemode = False
37- conn.config.display_limit = 25
37+ conn.config.display.limit = 25
3838
3939schema = dj.Schema(" my_schema" , connection = conn)
4040```
@@ -71,22 +71,68 @@ conn.config.stores = {...} # Configure stores for this connection
7171
7272## Implementation
7373
74- 1 . Add ` thread_safe: bool = False ` field to ` Config ` with ` DJ_THREAD_SAFE ` env alias
75- 2 . Make ` thread_safe ` always read-only after initialization
76- 3 . When ` thread_safe=True ` , make ` dj.config ` writes raise ` ThreadSafetyError `
77- 4 . Add guard to ` dj.conn() `
78- 5 . Add guard to ` Schema.__init__ ` when ` connection=None `
79- 6 . Add ` conn.config ` to ` Connection ` that copies from global ` dj.config `
80- 7 . Add ` ThreadSafetyError ` exception
74+ ### 1. Add thread_safe setting
75+ - Add ` thread_safe: bool = False ` field to ` Config ` with ` DJ_THREAD_SAFE ` env alias
76+ - Make ` thread_safe ` always read-only after initialization
77+ - When ` thread_safe=True ` , make ` dj.config ` writes raise ` ThreadSafetyError `
8178
82- ## Exceptions
79+ ### 2. Add guards for global state
80+ - ` dj.conn() ` : Raise ` ThreadSafetyError ` when ` thread_safe=True `
81+ - ` Schema.__init__ ` : Raise ` ThreadSafetyError ` when ` connection=None ` and ` thread_safe=True `
82+
83+ ### 3. Add conn.config
84+ - ` Connection.__init__ ` : Create ` self.config ` as copy of global ` dj.config `
85+ - ` conn.config ` is always mutable
86+
87+ ### 4. Refactor internal code to use conn.config
88+
89+ All runtime operations must use ` self.connection.config ` instead of global ` config ` :
90+
91+ ** table.py:**
92+ - ` Table.delete() ` : Use ` self.connection.config.safemode `
93+ - ` Table.drop() ` : Use ` self.connection.config.safemode `
94+
95+ ** schemas.py:**
96+ - ` Schema.drop() ` : Use ` self.connection.config.safemode `
97+ - ` Schema.__init__ ` : Use ` self.connection.config.database.create_tables `
98+
99+ ** preview.py:**
100+ - Use ` connection.config.display.limit `
101+ - Use ` connection.config.display.width `
102+ - Use ` connection.config.display.show_tuple_count `
103+ - Note: Preview functions need connection passed in or accessed via table
104+
105+ ** diagram.py:**
106+ - Use ` schema.connection.config.display.diagram_direction `
107+
108+ ** jobs.py:**
109+ - Use ` self.connection.config.jobs.* ` for all jobs settings
110+ - ` version_method ` , ` default_priority ` , ` stale_timeout ` , ` keep_completed `
111+
112+ ** autopopulate.py:**
113+ - Use ` self.connection.config.jobs.allow_new_pk_fields_in_computed_tables `
114+ - Use ` self.connection.config.jobs.auto_refresh `
115+
116+ ** declare.py:**
117+ - Use ` connection.config.jobs.add_job_metadata `
118+
119+ ** connection.py:**
120+ - Use ` self.config.database.reconnect ` for reconnect behavior
121+ - Use ` self.config.query_cache ` for query caching
122+
123+ ** hash_registry.py, staged_insert.py, builtin_codecs/\* :**
124+ - Use ` connection.config.get_store_spec() ` for store configuration
125+ - Use ` connection.config.download_path ` for downloads
126+
127+ ### 5. Add ThreadSafetyError exception
83128
84129``` python
85130class ThreadSafetyError (DataJointError ):
86131 """ Raised when modifying global state in thread-safe mode."""
87132```
88133
89- Error messages:
134+ ## Error Messages
135+
90136- Config write: ` "Global config is read-only in thread-safe mode. Use conn.config for connection-scoped settings." `
91137- ` dj.conn() ` : ` "dj.conn() is disabled in thread-safe mode. Use Connection() with explicit parameters." `
92138- Schema without connection: ` "Schema requires explicit connection in thread-safe mode." `
0 commit comments