@@ -28,6 +28,11 @@ class SchemaCodec(Codec, register=False):
2828 - ``_build_path()``: Construct storage path from context
2929 - ``_get_backend()``: Get storage backend by name
3030
31+ Both helpers take a ``config`` and fall back to the global ``dj.config``
32+ without one. Read it off ``key["_config"]`` and pass it through, as below: it
33+ is the calling connection's config, and in a process holding connections for
34+ several users the global one belongs to none of them.
35+
3136 Comparison with Hash-addressed:
3237 - **Schema-addressed** (this): Path from schema structure, no dedup
3338 - **Hash-addressed**: Path from content hash, automatic dedup
@@ -39,13 +44,18 @@ class MyCodec(SchemaCodec):
3944
4045 def encode(self, value, *, key=None, store_name=None):
4146 schema, table, field, pk = self._extract_context(key)
42- path, _ = self._build_path(schema, table, field, pk, ext=".dat")
43- backend = self._get_backend(store_name)
47+ config = (key or {}).get("_config")
48+ path, _ = self._build_path(
49+ schema, table, field, pk, ext=".dat",
50+ store_name=store_name, config=config,
51+ )
52+ backend = self._get_backend(store_name, config=config)
4453 backend.put_buffer(serialize(value), path)
4554 return {"path": path, "store": store_name, ...}
4655
4756 def decode(self, stored, *, key=None):
48- backend = self._get_backend(stored.get("store"))
57+ config = (key or {}).get("_config")
58+ backend = self._get_backend(stored.get("store"), config=config)
4959 return MyRef(stored, backend)
5060
5161 See Also
0 commit comments