Skip to content

Commit 3ca7c47

Browse files
committed
docs(codecs): thread the connection config in the SchemaCodec example
The subclass example omitted config= on both _build_path and _get_backend, so a codec written from it resolves its store against the module-level dj.config instead of the calling connection's. In a process holding connections for several users that config belongs to none of them, and on a pod with no ambient credentials it belongs to nothing at all. The built-in object and npy codecs already read key["_config"] and pass it to both helpers; the example now shows the same, and a note above it says why. The example also omitted store_name on _build_path, which is where partition and prefix settings come from. Docs only: the executable AST is unchanged.
1 parent 8e6ef31 commit 3ca7c47

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

src/datajoint/builtin_codecs/schema.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)