webhook: a first-time contributor's order must not vanish in silence
ci/woodpecker/push/woodpecker Pipeline was canceled
ci/woodpecker/push/woodpecker Pipeline was canceled
On 2026-11-13 21:59:43 Open Collective delivered order.processed for a live $5/month membership (Conor W, conor.canaday@gmail.com, order or_eU8gRkrPCvFsaYHrgiCfz). The portal answered 200 and did nothing. The membership branch resolves the payer by SLUG against the collective's members list: members = await fetch_members() member = next((m for m in members if m["slug"] == slug), None) and a first-time contributor's account is not in that list yet — OC reports the payer as guest-…/incognito-…. So `member` was None, the branch fell through, and because the delivery had SUCCEEDED there was no error to record either: no account, no welcome email, no credit, no log line. The sweep's unmapped-backers check found it hours later, which is the wrong place to find it. Now an unknown payer is resolved from the order's account slug (`Individual.email`, which OC exposes for an ordinary guest checkout) and handed to the same provisioning path a known member gets. When even that yields no email — an incognito profile, hidden on purpose — the webhook logs at ERROR that nobody was provisioned or credited, instead of shrugging. The defect worth naming is the SHAPE: an `if` with no `else` on a money path, where doing nothing leaves no trace. tests/test_resolve_payer.py pins the resolution cases (guest with email, incognito, unknown account, read failure, no token) and the fact that the branch can no longer fall through quietly.
This commit is contained in:
1 parent
27929987b2
commit
5a7380686c
2 files changed
+171
No files matched your search
+60
@@ -4191,6 +4191,30 @@ async def _process_opencollective_webhook(request: Request, token: str):
|
||||
# calendar (all members landing on Oct 1 otherwise).
|
||||
members = await fetch_members()
|
||||
member = next((m for m in members if m["slug"] == slug), None)
|
||||
if not member and slug:
|
||||
# A FIRST-TIME contributor's OC profile is usually not in the
|
||||
# collective's members list yet when their first order lands (OC
|
||||
# reports the payer as guest-…/incognito-…). The slug lookup then
|
||||
# finds nothing, and this branch used to fall straight through —
|
||||
# SILENTLY. The webhook answered 200, nobody was provisioned,
|
||||
# nothing was credited and nothing was logged. On 2026-11-13 that
|
||||
# cost conor.canaday@gmail.com his account and his welcome email
|
||||
# on a live $5/month membership; only the sweep's
|
||||
# unmapped-backers check noticed, hours later.
|
||||
payer = await fetch_account_by_slug(slug)
|
||||
email = (payer or {}).get("email")
|
||||
if email:
|
||||
member = {"email": email,
|
||||
"name": (payer or {}).get("name") or email.split("@")[0],
|
||||
"slug": slug}
|
||||
logger.warning(
|
||||
"Webhook: membership order from %s is not in the OC members "
|
||||
"list yet; resolved it to %s by account email", slug, email)
|
||||
else:
|
||||
logger.error(
|
||||
"Webhook: membership order from %s could not be resolved to an "
|
||||
"email (incognito profile); NOBODY was provisioned or credited — "
|
||||
"the sweep's unmapped-backers check must report this", slug)
|
||||
if member:
|
||||
# A contribution may arrive under a DIFFERENT email than the
|
||||
# portal account (a invited friend who joined under another OC
|
||||
@@ -7369,6 +7393,42 @@ def payment_reminder_email(name: str, contribute_url: str) -> tuple[str, str, st
|
||||
return subject, text, html
|
||||
|
||||
|
||||
async def fetch_account_by_slug(slug: str) -> dict | None:
|
||||
"""The Open Collective account behind a payer slug, with its email if OC gives it.
|
||||
|
||||
Orders report their payer as `fromAccount { slug }`. For a FIRST-TIME
|
||||
contributor that account is often not in the collective's members list yet
|
||||
(OC reports the payer as `guest-…`/`incognito-…`), which is exactly the case
|
||||
this exists for: it is the only way to learn who paid, and therefore the only
|
||||
way to provision them.
|
||||
|
||||
OC exposes `email` on the Individual fragment — visible for an ordinary guest
|
||||
checkout, null for an incognito profile (the contributor hid it on purpose).
|
||||
Returns None when the account cannot be read; NEVER raises, because its
|
||||
caller must be able to say "could not resolve" rather than die mid-webhook.
|
||||
"""
|
||||
slug = (slug or "").strip()
|
||||
if not slug or not OC_PERSONAL_TOKEN:
|
||||
return None
|
||||
query = ("query($slug: String!) { account(slug: $slug) { __typename id name slug "
|
||||
"... on Individual { email isIncognito } } }")
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=30.0) as client:
|
||||
data = await _oc_graphql_post(client, {"query": query, "variables": {"slug": slug}})
|
||||
except Exception as e: # read failure: report, never raise
|
||||
logger.warning("OC account lookup failed for slug %s: %s", slug, e)
|
||||
return None
|
||||
acct = ((data or {}).get("data") or {}).get("account") or None
|
||||
if not acct:
|
||||
return None
|
||||
if acct.get("isIncognito"):
|
||||
# Hidden on purpose: there is no email to provision from, and inventing
|
||||
# one from the slug would be worse than saying so.
|
||||
return {**acct, "email": None}
|
||||
acct["email"] = (acct.get("email") or "").strip().lower() or None
|
||||
return acct
|
||||
|
||||
|
||||
async def fetch_member_index() -> dict[str, dict]:
|
||||
"""email -> {slug, joined, role, tier} from the live OC member list.
|
||||
|
||||
|
||||
Reference in new issue
Block a user