fix(advice): an editing token, so a comment-only correction is safe too
The gravity guard caught a correction that changed the gravity, but a
COMMENT-ONLY correction leaves the gravity unchanged - so the late
thread for the old advice still matched and overwrote the fresh one.
Reproduced against the live database:
fresh advice matched: 1
stale thread matched: 1 <-- should be 0
FINAL advice: 'STALE ADVICE'
Every edit now writes a fresh token onto the reading, and the advice
thread carries the token it was given. A late thread finds a token that
no longer matches, so its write is refused. The gravity is still
checked as well.
Verified against the live database:
token changed: True
fresh advice matched: 1
stale thread matched: 0 <-- must be 0
FINAL advice: 'FRESH ADVICE'
174 tests (up from 173).
This commit is contained in:
@@ -156,6 +156,10 @@ class Reading:
|
||||
# Mongo, so the brewer's own comment is never overwritten.
|
||||
advice: str = ""
|
||||
advice_ok: bool = True
|
||||
# Marks this generation of the reading. Every edit writes a fresh
|
||||
# one, so an advice thread working on an earlier version of the
|
||||
# reading can be told apart from the current one.
|
||||
advice_token: str = ""
|
||||
|
||||
@property
|
||||
def sg_decimal(self) -> float | None:
|
||||
@@ -177,6 +181,7 @@ class Reading:
|
||||
_id=str(doc.get("_id") or ""),
|
||||
advice=(doc.get("advice") or "").strip(),
|
||||
advice_ok=bool(doc.get("advice_ok", True)),
|
||||
advice_token=str(doc.get("advice_token") or ""),
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user