Open
Description
Issue Summary
The SubscriptionTracking object attempts to serialize its components with a get
call (https://github.com/sendgrid/sendgrid-python/blob/main/sendgrid/helpers/mail/subscription_tracking.py#L134), but as per those attribute definitions (https://github.com/sendgrid/sendgrid-python/blob/main/sendgrid/helpers/mail/subscription_tracking.py#L57, et. al.), the text
, html
, and substitution_tag
values are intended to be strings, which obviously would not have a get
method.
Steps to Reproduce
- Create a SubscriptionTracking object and assign it to a Mail object
- Call the Mail object's
get()
serializer
Code Snippet
The simplest way to reproduce this is:
from sendgrid import SubscriptionTracking
x = SubscriptionTracking(text='foo')
x.get()
The broader implication is that having a SubscriptionTracking object attached to your Mail object completely sinks your ability to serialize the Mail object due to the nested nature of the get() calls:
from sendgrid import Mail, SubscriptionTracking, TrackingSettings
msg = Mail(plain_text_content='foo')
x = SubscriptionTracking()
x.enable = True
x.text = 'foo'
ts = TrackingSettings(subscription_tracking=x)
msg.tracking_settings = ts
msg.get()
Exception/Log
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-14-21057a958240> in <module>
----> 1 msg.get()
/usr/local/lib/python3.8/site-packages/sendgrid/helpers/mail/mail.py in get(self)
980 'ip_pool_name': self._get_or_none(self.ip_pool_name),
981 'mail_settings': self._get_or_none(self.mail_settings),
--> 982 'tracking_settings': self._get_or_none(self.tracking_settings),
983 'reply_to': self._get_or_none(self.reply_to),
984 }
/usr/local/lib/python3.8/site-packages/sendgrid/helpers/mail/mail.py in _get_or_none(self, from_obj)
131 :type from_obj: obj
132 """
--> 133 return from_obj.get() if from_obj is not None else None
134
135 def _set_emails(
/usr/local/lib/python3.8/site-packages/sendgrid/helpers/mail/tracking_settings.py in get(self)
129 if self.subscription_tracking is not None:
130 tracking_settings[
--> 131 "subscription_tracking"] = self.subscription_tracking.get()
132 if self.ganalytics is not None:
133 tracking_settings["ganalytics"] = self.ganalytics.get()
/usr/local/lib/python3.8/site-packages/sendgrid/helpers/mail/subscription_tracking.py in get(self)
132
133 if self.text is not None:
--> 134 subscription_tracking["text"] = self.text.get()
135
136 if self.html is not None:
AttributeError: 'str' object has no attribute 'get'
Technical details:
- sendgrid-python version: originally found in 6.4.8, verified in 6.6.0
- python version: 3.8.7