F30: a process holding an older release's hermes_state still gets a store from the registry
A long-running process from an older release (an ACP server across hermes update) has that release's hermes_state loaded and imports hermes_state_registry lazily from the new tree. acquire read the stand-in's private _first_warning, which the older module lacks, so the import raised AttributeError and the server's _get_db swallowed it and went without a store. acquire now looks the helper up and, when the loaded hermes_state is not the stand-in, opens that module's own SessionDB, without the deprecation warning. The case loads an older-shaped hermes_state, then the registry: it failed with that AttributeError (0/1) and passes (1/0); the stand-in, shared-registry and logger-name suites pass (38, 1, 1). Reported-by: teknium1
This commit is contained in:
@@ -2,7 +2,8 @@
|
||||
|
||||
``acquire`` opens a ``hermes_state.SessionDB`` on the storage interface and ``release`` closes it; nothing is shared
|
||||
between callers. The first ``acquire`` in a process emits the ``hermes_state`` stand-in's one deprecation warning,
|
||||
unless another stand-in name has already emitted it.
|
||||
unless another stand-in name has already emitted it. A process that loaded an older release's ``hermes_state`` before
|
||||
an update (a long-running server importing this module lazily) gets that release's ``SessionDB``, without the warning.
|
||||
"""
|
||||
|
||||
import warnings as _warnings
|
||||
@@ -12,7 +13,10 @@ import hermes_state as _hermes_state
|
||||
|
||||
def acquire(db_path=None):
|
||||
"""A ``hermes_state.SessionDB`` on the store of ``db_path`` (a ``state.db``), or of the current profile."""
|
||||
if _hermes_state._first_warning():
|
||||
first_warning = getattr(_hermes_state, "_first_warning", None)
|
||||
if first_warning is None:
|
||||
return _hermes_state.SessionDB(db_path)
|
||||
if first_warning():
|
||||
_warnings.warn(
|
||||
f"hermes_state_registry.acquire is deprecated and is removed in {_hermes_state._REMOVAL_RELEASE}; use "
|
||||
f"persistence_assembly.open_persistence(profile_scope()) instead ({_hermes_state._MIGRATION_GUIDE}).",
|
||||
|
||||
25
tests/test_hermes_state_registry_old_release.py
Normal file
25
tests/test_hermes_state_registry_old_release.py
Normal file
@@ -0,0 +1,25 @@
|
||||
"""A process that loaded an older release's ``hermes_state`` before ``hermes update`` still gets a store from the
|
||||
registry module it imports lazily afterwards."""
|
||||
|
||||
import importlib
|
||||
import sys
|
||||
import types
|
||||
|
||||
|
||||
class _OldReleaseSessionDB:
|
||||
def __init__(self, db_path=None):
|
||||
self.db_path = db_path
|
||||
|
||||
|
||||
def test_acquire_under_an_older_loaded_hermes_state_opens_that_releases_session_db(monkeypatch, tmp_path):
|
||||
old = types.ModuleType("hermes_state")
|
||||
old.SessionDB = _OldReleaseSessionDB # type: ignore[attr-defined]
|
||||
monkeypatch.setitem(sys.modules, "hermes_state", old)
|
||||
monkeypatch.delitem(sys.modules, "hermes_state_registry", raising=False)
|
||||
registry = importlib.import_module("hermes_state_registry")
|
||||
try:
|
||||
db = registry.acquire(tmp_path / "state.db")
|
||||
assert isinstance(db, _OldReleaseSessionDB)
|
||||
assert db.db_path == tmp_path / "state.db"
|
||||
finally:
|
||||
sys.modules.pop("hermes_state_registry", None)
|
||||
Reference in New Issue
Block a user