Fix spurious re-sync/preview for campaigns without an explicit template_id
CI / test (push) Successful in 21s

campaignUnchanged compared input.TemplateID (0 when unset) literally
against existing.TemplateID, but listmonk always assigns a real, nonzero
template_id server-side even when create/update omits it. Every campaign
without an explicit template_id was therefore flagged "changed" on every
sync, forever, firing an unwanted extra preview email each time — caught
via reground-campaigns' welcome/campaign.md re-previewing on an unrelated
push. Treat TemplateID 0 as "don't compare" instead. Test fake now mirrors
listmonk's real default-assignment behavior so this class of bug is caught.
This commit is contained in:
2026-08-13 11:35:52 -04:00
parent 6227d59eae
commit 0c8bc6bd3b
2 changed files with 55 additions and 3 deletions
+7 -1
View File
@@ -222,7 +222,13 @@ func campaignUnchanged(existing *listmonk.Campaign, input listmonk.CampaignInput
// stored altbody is still null even though its body hasn't changed.
existing.AltBody == input.Body &&
existing.FromEmail == input.FromEmail &&
existing.TemplateID == input.TemplateID &&
// input.TemplateID == 0 means "unspecified, use whatever's assigned"
// (see CampaignInput.TemplateID) -- listmonk always assigns some real,
// nonzero template_id server-side even when it's omitted from the
// create/update payload, so comparing 0 against that would flag every
// campaign.md without an explicit template_id as changed on every
// sync, forever.
(input.TemplateID == 0 || existing.TemplateID == input.TemplateID) &&
existing.Type == input.Type &&
equalStringSets(existing.Tags, input.Tags) &&
equalIntSets(existing.ListIDs, input.ListIDs) &&