-
Notifications
You must be signed in to change notification settings - Fork 731
Closed
Description
Issue Summary
senndgrid.helpers.mail.mail.Mail.add_custom_args() raises AttributeError: 'dict' object has no attribute 'personalization' from within the sendgrid library
How am I using it?
- I have created a Mail object and then called the
mail.add_custom_arg({"email_id": str(uuid4())})
which state is should accept a dict type argument.
Code where its happening
def add_custom_arg(self, custom_arg):
"""Add custom args to the email globaly or to a specific Personalization
:param value: A CustomArg object or a dict of custom arg key/values
:type value: CustomArg, dict
"""
if custom_arg.personalization is not None:
try:
personalization = \
self._personalizations[custom_arg.personalization]
has_internal_personalization = True
except IndexError:
personalization = Personalization()
has_internal_personalization = False
if isinstance(custom_arg, dict):
(k, v) = list(custom_arg.items())[0]
personalization.add_custom_arg(CustomArg(k, v))
else:
personalization.add_custom_arg(custom_arg)
if not has_internal_personalization:
self.add_personalization(
personalization, index=custom_arg.personalization)
else:
if isinstance(custom_arg, dict):
(k, v) = list(custom_arg.items())[0]
self._custom_args = self._ensure_append(
CustomArg(k, v), self._custom_args)
else:
self._custom_args = self._ensure_append(
custom_arg, self._custom_args)
Steps to Reproduce
- Call add_custom_args with a dictionary argument
Code Snippet
message = Mail(
from_email=os.getenv("SENDER_EMAIL"),
to_emails=addresses,
subject=subject,
html_content=html_str,
)
# Unique ID used to get from webhook
internal_email_id = str(uuid4())
message.add_custom_arg({"internal_email_id": internal_email_id})
Exception/Log
self = <sendgrid.helpers.mail.mail.Mail object at 0x7f9a6ddc42b0>
custom_arg = {'internal_email_id': xxxxxxx-xxxx-9xxxx-xxxxxxxxx'}
def add_custom_arg(self, custom_arg):
"""Add custom args to the email globaly or to a specific Personalization
:param value: A CustomArg object or a dict of custom arg key/values
:type value: CustomArg, dict
"""
> if custom_arg.personalization is not None:
E AttributeError: 'dict' object has no attribute 'personalization'
Technical Details
- sendgrid-python: version 6.11.0
- python version: 3.12.7
Metadata
Metadata
Assignees
Labels
No labels