panel state: a reminder is history, not a state — renewals clear grace, grace expires
ci/woodpecker/push/woodpecker Pipeline was canceled
ci/woodpecker/push/woodpecker Pipeline was canceled
mark@ofosos.org showed as in grace while his contribution was live. The sweep's own trail says it plainly: reminded 2026-11-04 for the cycle that looked unpaid, grace elapsed 2026-11-11, and `renewed` logged at 19:02 on 2026-11-13 (last charge 2026-11-11, next reset 2026-11-26). The panel said grace anyway, because member_membership_state() asked only "is there a row in payment_reminders?". That table is a HISTORY — kept so the sweep does not re-remind inside a cycle. It is not a state, and treating it as one broke two things: a reminder never expired (grace is PAYMENT_GRACE_DAYS long), and a renewal never cleared it. Now the LATEST reconciliation decision decides: renewed / would_renew -> active (they are paying) reminder inside the window -> in_grace reminder past the window -> awaiting_contribution, saying grace elapsed would_deactivate / deactivated -> awaiting_contribution Ordered by decided_at, not id: the same member had id 2296 dated 2026-11-11 next to id 2286 dated 2026-11-13, so "latest by id" reads the wrong decision. Reads still fail safe: an unreadable DB reports active, never a payment problem. tests/test_membership_state.py pins all of it, including the ordering trap.
This commit is contained in:
1 parent
b1f5a30272
commit
241ac800c6
2 files changed
+161
-13
No files matched your search
+39
-13
@@ -7064,34 +7064,60 @@ def member_membership_state(email: str, active: bool) -> tuple[str, str]:
|
||||
the portal rather than inventing policy of its own:
|
||||
|
||||
inactive — membership deactivated (members.active = 0).
|
||||
in_grace — a payment reminder has been sent for this member's
|
||||
current cycle and no contribution has arrived yet;
|
||||
access continues for PAYMENT_GRACE_DAYS.
|
||||
awaiting_contribution — the reconciliation flagged the member unpaid but no
|
||||
reminder has been sent yet.
|
||||
active — current / no open reminder.
|
||||
in_grace — a payment reminder went out and we are still inside
|
||||
the PAYMENT_GRACE_DAYS window.
|
||||
awaiting_contribution — the member is unpaid: either flagged with no
|
||||
reminder yet, or the grace window has elapsed
|
||||
(deactivation pending).
|
||||
active — current.
|
||||
|
||||
THE REMINDER TABLE IS A HISTORY, NOT A STATE. A row stays after the member
|
||||
pays, so "a reminder exists" is not "they are in grace". On 2026-11-13
|
||||
mark@ofosos.org showed as in grace while his contribution was live: reminded
|
||||
2026-11-04, grace elapsed 2026-11-11, and the reconciliation logged `renewed`
|
||||
for him at 19:02 that afternoon. The old version returned grace from the
|
||||
reminder row alone, forever.
|
||||
|
||||
So the LATEST RECONCILIATION DECISION decides, and a past reminder only
|
||||
matters when nothing since says they paid. Ordered by decided_at, not id:
|
||||
ids come from insertion order and a later-inserted row can carry an earlier
|
||||
timestamp (the same member had id 2296 dated 11-11 next to id 2286 dated
|
||||
11-13).
|
||||
"""
|
||||
if not active:
|
||||
return "inactive", "deactivated"
|
||||
try:
|
||||
conn = get_db()
|
||||
latest = conn.execute(
|
||||
"SELECT decision, decided_at FROM allowance_log WHERE email = ? "
|
||||
"ORDER BY decided_at DESC, id DESC LIMIT 1",
|
||||
(email,),
|
||||
).fetchone()
|
||||
rem = conn.execute(
|
||||
"SELECT sent_at FROM payment_reminders WHERE email = ? "
|
||||
"ORDER BY sent_at DESC LIMIT 1",
|
||||
(email,),
|
||||
).fetchone()
|
||||
log = conn.execute(
|
||||
"SELECT decision FROM allowance_log WHERE email = ? ORDER BY id DESC LIMIT 1",
|
||||
(email,),
|
||||
).fetchone()
|
||||
conn.close()
|
||||
except Exception: # tables absent / unreadable: fail safe
|
||||
return "active", ""
|
||||
decision = (latest[0] if latest else "") or ""
|
||||
if decision in ("renewed", "would_renew"):
|
||||
# They are paying. Any reminder belongs to an earlier cycle.
|
||||
return "active", ""
|
||||
if rem:
|
||||
return "in_grace", (f"awaiting contribution — reminder sent "
|
||||
f"{str(rem[0])[:10]}, grace {int(PAYMENT_GRACE_DAYS)}d")
|
||||
if log and log[0] in ("reminded", "would_remind", "remind_failed"):
|
||||
sent = _parse_oc_dt(str(rem[0])) if rem[0] else None
|
||||
within = sent is not None and (datetime.now(timezone.utc) - sent) <= timedelta(days=PAYMENT_GRACE_DAYS)
|
||||
if within:
|
||||
return "in_grace", (f"awaiting contribution — reminder sent "
|
||||
f"{str(rem[0])[:10]}, grace {int(PAYMENT_GRACE_DAYS)}d")
|
||||
return "awaiting_contribution", (
|
||||
f"unpaid — reminder sent {str(rem[0])[:10]}, grace of "
|
||||
f"{int(PAYMENT_GRACE_DAYS)}d elapsed, deactivation pending")
|
||||
if decision in ("reminded", "would_remind", "remind_failed"):
|
||||
return "awaiting_contribution", "no current contribution at Open Collective"
|
||||
if decision in ("would_deactivate", "deactivated"):
|
||||
return "awaiting_contribution", f"grace elapsed ({decision})"
|
||||
return "active", ""
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user