-
Notifications
You must be signed in to change notification settings - Fork 728
Open
Labels
status: waiting for feedbackwaiting for feedback from the submitterwaiting for feedback from the submittertype: questionquestion directed at the libraryquestion directed at the library
Description
Issue Summary
I am trying to determine why using add_personalization removes the existing dynamic_template_data I already set on my mail object. If this is desired behavior, I would have expected some kind of note about it in the docs, or preferably a warning in the code.
I tried looking in the knowledge base, on github issues, and on stack overflow. I could not find anything to suggest why this might be happening. I found the workaround by simply resetting dynamic_template_data. I could, of course, simply add the personalization first and then add the dynamic_template_data, but this seemed like a silent gotcha that should be brought to the sendgrid team's awareness.
Steps to Reproduce
- Attach dynamic template data to mail object
- Have cc recipients, so add personalization to mail object
- Dynamic template data is now empty
Code Snippet
def our_simplified_send_func(to_, template_id, template_data, cc_recipients = []):
mail = Mail(from_email=self._from, to_emails=_to) # self._from is a class var
mail.dynamic_template_data = template_data
mail.template_id = template_id
if len(cc_recipients) > 0:
sendgrid_personalization = Personalization()
for cc in cc_recipients:
sendgrid_personalization.add_cc( To(cc, cc) )
for to_recipient in to_:
sendgrid_personalization.add_to( To(to_recipient, to_recipient) )
mail.add_personalization(sendgrid_personalization)
# Why do I need to re-add dynamic_template_data after adding a personalization?
mail.dynamic_template_data = template_dataException/Log
It's not an explicit exception or error log so much as running `add_personalization` removes the existing dynamic_template_data.
Technical details:
- sendgrid-python version: 6.4.8
- python version: 3.8.12
Metadata
Metadata
Assignees
Labels
status: waiting for feedbackwaiting for feedback from the submitterwaiting for feedback from the submittertype: questionquestion directed at the libraryquestion directed at the library