Skip to content

Commit 4685eda

Browse files
Document register_adapter process-global scope and unregister pattern
The register_adapter docstring noted "stdlib pre-3.12 semantics" but did not warn psycopg porters about the divergence from psycopg3's per-connection AdaptersMap. Tests that register adapters in pytest fixtures silently leak between tests under dqlite's process-global registry. Document: - Scope is process-global (matches stdlib sqlite3 pre-3.12). - psycopg3-style per-connection scoping is NOT supported. - Tests should clean up explicitly. - register_adapter(type_, None) does NOT unregister (raises TypeError on the callable check); use _ADAPTERS.pop(type_, None) for explicit removal in test fixtures. Pure docstring change. No behavioural impact. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 87f429f commit 4685eda

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

src/dqlitedbapi/types.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,23 @@ def register_adapter(type_: type, adapter: "Any") -> None:
559559
dispatched on read. Callers wanting per-row decoding can use
560560
``Cursor.row_factory`` (when implemented) or post-fetch
561561
coercion in user code.
562+
563+
**Scope: process-global.** Adapters live in a single module-
564+
level dict shared by every sync and async connection in the
565+
process — registering on either ``dqlitedbapi`` or
566+
``dqlitedbapi.aio`` mutates the same dict. This matches stdlib
567+
``sqlite3.register_adapter`` pre-3.12 semantics. psycopg3-style
568+
per-connection scoping (``Connection.adapters``) is NOT
569+
supported: registering here affects every connection in the
570+
process. Tests that register adapters should clean up by
571+
explicitly removing the entry afterwards. Note that calling
572+
``register_adapter(type_, None)`` does NOT unregister — it
573+
raises ``TypeError`` because ``None`` fails the
574+
callable-check above. To remove an adapter, access the
575+
private registry directly:
576+
``from dqlitedbapi.types import _ADAPTERS;
577+
_ADAPTERS.pop(type_, None)``. This is internal and acceptable
578+
for test cleanup; production code should not rely on it.
562579
"""
563580
if not callable(adapter):
564581
raise TypeError(f"adapter must be callable, got {type(adapter).__name__}")

0 commit comments

Comments
 (0)