SendGrid: Fix multiple recipients with only merge_global_data

In SendGrid backend, support non-batch template send to multiple
recipients when `merge_global_data` is set without `merge_data`.
Regression introduced in v6.0.

Fixes #179
This commit is contained in:
Mike Edmunds
2020-03-18 17:08:10 -04:00
committed by GitHub
parent 4245d468ec
commit 920d8dd70f
3 changed files with 30 additions and 1 deletions

View File

@@ -133,8 +133,9 @@ class SendGridPayload(RequestsPayload):
if self.merge_data or self.merge_global_data:
# Always build dynamic_template_data first,
# then convert it to legacy template format if needed
only_global_merge_data = self.merge_global_data and not self.merge_data
for personalization in self.data["personalizations"]:
assert len(personalization["to"]) == 1
assert len(personalization["to"]) == 1 or only_global_merge_data
recipient_email = personalization["to"][0]["email"]
dynamic_template_data = self.merge_global_data.copy()
dynamic_template_data.update(self.merge_data.get(recipient_email, {}))