fix(trucking): refresh subscriber attribs for existing carriers on re-import

add_subscriber only attached existing subscribers to the new list without
updating attribs, so a carrier emailed in a prior campaign kept STALE attribs --
meaning the daily coupon code and IFTA merge fields (ifta_due_date, ifta_quarter,
lp_link) rendered BLANK for any repeat recipient. Now merge+PUT the fresh attribs
on the existing subscriber before attaching. Affects all trucking campaigns, not
just IFTA. Verified: IFTA preview now persists ifta_quarter/ifta_due_date/lp_link.
This commit is contained in:
justin 2026-06-13 23:26:47 -05:00
parent 19bbef3231
commit 872154ebf7

View file

@ -433,8 +433,24 @@ def add_subscriber(list_id: int, email: str, name: str, attribs: dict) -> bool:
if status != "enabled":
LOG.info("Listmonk suppressed existing subscriber %s status=%s", email, status or "unknown")
return False
sub_id = results[0]["id"]
# Refresh attribs so per-campaign merge fields (coupon code,
# ifta_due_date, lp_link, etc.) are correct for THIS send --
# otherwise a previously-imported carrier keeps stale attribs
# and the new campaign renders blank fields.
try:
merged = dict(results[0].get("attribs") or {})
merged.update(attribs or {})
lm_api(f"/subscribers/{sub_id}", {
"email": email,
"name": name or results[0].get("name") or email,
"status": "enabled",
"attribs": merged,
}, "PUT")
except Exception:
pass # non-fatal: still attach to the list below
lm_api("/subscribers/lists", {
"ids": [results[0]["id"]],
"ids": [sub_id],
"action": "add",
"target_list_ids": [list_id],
"status": "confirmed",