Title: Setting Personalization Removes Existing template_data · Issue #1037 · sendgrid/sendgrid-python · GitHub
Open Graph Title: Setting Personalization Removes Existing template_data · Issue #1037 · sendgrid/sendgrid-python
X Title: Setting Personalization Removes Existing template_data · Issue #1037 · sendgrid/sendgrid-python
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, o...
Open Graph 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 s...
X 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 s...
Opengraph URL: https://github.com/sendgrid/sendgrid-python/issues/1037
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Setting Personalization Removes Existing template_data","articleBody":"### Issue Summary\r\nI 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.\r\n\r\nI 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.\r\n\r\n### Steps to Reproduce\r\n1. Attach dynamic template data to mail object\r\n2. Have cc recipients, so add personalization to mail object\r\n3. Dynamic template data is now empty\r\n\r\n### Code Snippet\r\n```python\r\ndef our_simplified_send_func(to_, template_id, template_data, cc_recipients = []):\r\n mail = Mail(from_email=self._from, to_emails=_to) # self._from is a class var\r\n mail.dynamic_template_data = template_data\r\n mail.template_id = template_id\r\n\r\n if len(cc_recipients) > 0:\r\n sendgrid_personalization = Personalization()\r\n\r\n for cc in cc_recipients:\r\n sendgrid_personalization.add_cc( To(cc, cc) )\r\n\r\n for to_recipient in to_:\r\n sendgrid_personalization.add_to( To(to_recipient, to_recipient) )\r\n mail.add_personalization(sendgrid_personalization)\r\n\r\n # Why do I need to re-add dynamic_template_data after adding a personalization?\r\n mail.dynamic_template_data = template_data\r\n```\r\n\r\n### Exception/Log\r\n```\r\nIt's not an explicit exception or error log so much as running `add_personalization` removes the existing dynamic_template_data.\r\n```\r\n\r\n### Technical details:\r\n* sendgrid-python version: 6.4.8\r\n* python version: 3.8.12\r\n\r\n","author":{"url":"https://github.com/jr-bespoke","@type":"Person","name":"jr-bespoke"},"datePublished":"2022-01-24T23:36:53Z","url":"https://github.com/sendgrid/sendgrid-python/issues/1037"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:24ce5296-6e17-39a2-ac41-23d3dbb93710 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DD24:1D768B:AC77FA:DF6596:6B063880 |
| html-safe-nonce | 7eeb12128c976e0210883f5a9197e701dd275fda363e2b51c42ba10243926511 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERDI0OjFENzY4QjpBQzc3RkE6REY2NTk2OjZCMDYzODgwIiwidmlzaXRvcl9pZCI6IjU5Nzk4NDUyMzE0MTM5NjYwOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | fd7f68533da543906c62dcbd66d7765d7399d35cb18b85823ea5fab27f51a8ce |
| hovercard-subject-tag | issue:1113258615 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/sendgrid/sendgrid-python/1037/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b99e5feed774dd34a4d91c862f03d6cad171131aa38eef0681cb9084f58059f5/sendgrid/sendgrid-python/issues/1037 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b99e5feed774dd34a4d91c862f03d6cad171131aa38eef0681cb9084f58059f5/sendgrid/sendgrid-python/issues/1037 |
| og:image:alt | 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 s... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jr-bespoke |
| hostname | github.com |
| expected-hostname | github.com |
| None | dcf72c457c022486d23c3cbb0dd21aba537a87611ca9ddabd1799cf2eaa9b297 |
| turbo-cache-control | no-preview |
| go-import | github.com/sendgrid/sendgrid-python git https://github.com/sendgrid/sendgrid-python.git |
| octolytics-dimension-user_id | 181234 |
| octolytics-dimension-user_login | sendgrid |
| octolytics-dimension-repository_id | 3546794 |
| octolytics-dimension-repository_nwo | sendgrid/sendgrid-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 3546794 |
| octolytics-dimension-repository_network_root_nwo | sendgrid/sendgrid-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 0f38f5735226749ec5e08a8649dce4cb2613d9ad |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width