From 6c8c823e5e5fd4075e39c9a52009667df41ab987 Mon Sep 17 00:00:00 2001 From: justin Date: Fri, 12 Jun 2026 19:37:01 -0500 Subject: [PATCH] hc: refresh attribs when cross-adding an existing subscriber to a segment add_subscriber only attached an already-existing subscriber to the new list without updating attribs, so the due-soon template's days_until merge field was blank for providers already imported by another segment. Now PUT the merged attribs (existing + this segment's npi/practice/due-date/days_until) before adding to the list. --- scripts/build_healthcare_campaigns_cron.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/scripts/build_healthcare_campaigns_cron.py b/scripts/build_healthcare_campaigns_cron.py index b25ed78..faf3049 100644 --- a/scripts/build_healthcare_campaigns_cron.py +++ b/scripts/build_healthcare_campaigns_cron.py @@ -191,7 +191,9 @@ def add_subscriber(list_id: int, email: str, name: str, attribs: dict) -> bool: }) return True except SystemExit as e: - # Already exists -> attach to the list instead. + # Already exists -> attach to the list AND refresh attribs so per-segment + # merge fields (e.g. days_until for the due-soon template) are correct + # even when the same provider already exists from another segment import. if "409" in str(e) or "already exists" in str(e).lower(): try: q = "subscribers.email = '" + email.replace("'", "''") + "'" @@ -199,6 +201,14 @@ def add_subscriber(list_id: int, email: str, name: str, attribs: dict) -> bool: results = found.get("data", {}).get("results", []) if results: sid = results[0]["id"] + existing_attribs = results[0].get("attribs") or {} + # Merge: keep prior fields, overwrite with this segment's + # values (npi/practice/due-date/days_until/days_overdue). + merged = {**existing_attribs, **attribs} + lm(f"/subscribers/{sid}", { + "email": email, "name": name or email.split("@")[0], + "attribs": merged, + }, "PUT") lm("/subscribers/lists", {"ids": [sid], "action": "add", "target_list_ids": [list_id], "status": "confirmed"}, "PUT")