fix(family): undoing the decision that created an idea leaves no applicability or scope behind (#4989)
CI & Build / Python lint (push) Successful in 3s
CI & Build / Plugin hooks (push) Successful in 16s
CI & Build / TypeScript typecheck (push) Successful in 53s
CI & Build / integration (push) Successful in 56s
CI & Build / Python tests (push) Successful in 1m56s
CI & Build / Build & push image (push) Successful in 46s

When the undone decision had no recorded before-state, the synthesized prior copied the canon idea's current applies_when and platforms into a retired row. Before that decision the record was not an idea, so the restored state now has neither. Caught by test_undoing_a_promotion_restores_the_prior_state_and_keeps_judged_rows (run 8281).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-06 10:37:37 -04:00
co-authored by Claude Opus 5.5
parent 8aacc1824c
commit faa1b72307
+5 -2
View File
@@ -620,9 +620,12 @@ async def undo(user_id: int, decision_id: int, *, reason: str, decided_via: str
raise ValueError(f"decision {decision_id} cannot be undone: {why}") raise ValueError(f"decision {decision_id} cannot be undone: {why}")
idea = await session.get(FamilyIdea, target.idea_id) idea = await session.get(FamilyIdea, target.idea_id)
before = await _snapshot(session, idea) before = await _snapshot(session, idea)
# No recorded prior state means the decision CREATED the idea: before
# it, the record had no applicability test and no scope. It comes back
# as retired, with neither, rather than being deleted with its log.
prior = target.before or { prior = target.before or {
"status": "retired", "applies_when": idea.applies_when or "", "status": "retired", "applies_when": "",
"canon_version": idea.canon_version, "platforms": before["platforms"], "canon_version": idea.canon_version, "platforms": [],
} }
if prior["status"] == "canon" and not (prior.get("applies_when") or "").strip(): if prior["status"] == "canon" and not (prior.get("applies_when") or "").strip():
raise ValueError("the recorded prior state is canon with no 'applies when'") raise ValueError("the recorded prior state is canon with no 'applies when'")