Document kanta.ctx as the app-context channel for logemit
kanta.ctx already existed as a user-writable namespace for migrations; since LogEvent carries the kanta instance, ev.kanta.ctx is also the way for applications to pass per-connection metadata to their logemit callbacks, including for creation/bootstrap events. No API change needed.
This commit is contained in:
@@ -344,3 +344,18 @@ def test_header_is_settable_and_used_by_default_emit(capsys):
|
||||
err = capsys.readouterr().err
|
||||
assert "CUSTOM update" in err
|
||||
assert "counter" in err # default diff routing still applies
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_ctx_reachable_from_event(tmp_path, format_config):
|
||||
path = tmp_path / "test.db"
|
||||
kanta = make_kanta(path, Data, format_config)
|
||||
kanta.ctx.connection_id = 7
|
||||
seen = []
|
||||
kanta.logemit(lambda ev: seen.append(ev.kanta.ctx.connection_id) or True)
|
||||
await kanta.open()
|
||||
with kanta.transaction(action="inc") as data:
|
||||
data.counter = 1
|
||||
await kanta.close()
|
||||
|
||||
assert seen and all(connection_id == 7 for connection_id in seen)
|
||||
|
||||
Reference in New Issue
Block a user