From 872154ebf786786554f0c3866f52e2700b7209b2 Mon Sep 17 00:00:00 2001 From: justin Date: Sat, 13 Jun 2026 23:26:47 -0500 Subject: [PATCH] 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. --- scripts/build_trucking_campaigns.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/scripts/build_trucking_campaigns.py b/scripts/build_trucking_campaigns.py index d459290..4a9e10f 100644 --- a/scripts/build_trucking_campaigns.py +++ b/scripts/build_trucking_campaigns.py @@ -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",