Include extra also on transaction abort messages.
This commit is contained in:
+2
-1
@@ -242,7 +242,8 @@ def resolve_user_key(value: str) -> str | None:
|
||||
emitters can reuse as-is or replace piecemeal:
|
||||
- `event.header` — a lazy property producing the default one-line header
|
||||
for any kind: `<action>[ <extra>][ by <user>]` for changes,
|
||||
`<action>[ by <user>] transaction aborted: <error>` for aborts, and the
|
||||
`<action>[ <extra>][ by <user>] transaction aborted: <error>` for aborts,
|
||||
and the
|
||||
plain `Created`/`Migrated` summaries. It is settable: assign
|
||||
`event.header = ...` and return truthy to restyle the header while
|
||||
keeping the default diff routing.
|
||||
|
||||
+5
-2
@@ -74,8 +74,9 @@ class LogEvent(msgspec.Struct, kw_only=True):
|
||||
"""The default one-line header for this event, built on first access.
|
||||
|
||||
Covers every event kind: ``"<action>[ <extra>][ by <user>]"`` for
|
||||
changes, ``"<action>[ by <user>] transaction aborted: <error>"`` for
|
||||
aborts, and the plain ``Created``/``Migrated`` summaries.
|
||||
changes, ``"<action>[ <extra>][ by <user>] transaction aborted:
|
||||
<error>"`` for aborts, and the plain ``Created``/``Migrated``
|
||||
summaries.
|
||||
"""
|
||||
if self._header is None:
|
||||
self._header = self._build_header()
|
||||
@@ -102,6 +103,8 @@ class LogEvent(msgspec.Struct, kw_only=True):
|
||||
if self.kind == "change":
|
||||
return format_action_header(self.action or "", self.user, self.extra)
|
||||
line = Line().action(self.action or "")
|
||||
if self.extra:
|
||||
line(" ").target(self.extra)
|
||||
if self.user:
|
||||
line(" by ").user(self.user)
|
||||
line(f" transaction aborted: {self.error}")
|
||||
|
||||
@@ -124,6 +124,7 @@ def transaction(
|
||||
kanta=impl._kanta,
|
||||
action=action,
|
||||
user=resolved_user,
|
||||
extra=extra,
|
||||
error=exc,
|
||||
),
|
||||
impl.callback_registry.logemit_handlers,
|
||||
|
||||
@@ -282,12 +282,13 @@ async def test_aborted_transaction_includes_resolved_user(
|
||||
await kanta.open()
|
||||
with caplog.at_level(logging.WARNING, logger="kanta.transaction"):
|
||||
with pytest.raises(ValueError):
|
||||
with kanta.transaction(action="reset", user="u1") as data:
|
||||
with kanta.transaction(action="reset", user="u1", extra="exp") as data:
|
||||
data.counter = 99
|
||||
raise ValueError("boom")
|
||||
await kanta.close()
|
||||
|
||||
messages = [r.getMessage() for r in caplog.records if r.levelno == logging.WARNING]
|
||||
assert any("exp" in m for m in messages)
|
||||
assert any(" by " in m and "Alice" in m for m in messages)
|
||||
assert any(" transaction aborted: boom" in m for m in messages)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user