Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

SubscriptionTracking objects with a text, html, or substitution_tag attribute cannot be serialized #979

Open
putnamp opened this issue Mar 13, 2021 · 1 comment
Labels
status: help wanted requesting help from the community type: bug bug in the library

Comments

@putnamp
Copy link

putnamp commented Mar 13, 2021

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

  1. Create a SubscriptionTracking object and assign it to a Mail object
  2. 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
@JenniferMah JenniferMah added help wanted type: bug bug in the library labels Mar 15, 2021
@JenniferMah
Copy link
Contributor

This issue has been added to our internal backlog to be prioritized. Pull requests and +1s on the issue summary will help it move up the backlog

@childish-sambino childish-sambino added status: help wanted requesting help from the community and removed help wanted labels Mar 31, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
status: help wanted requesting help from the community type: bug bug in the library
Projects
None yet
Development

No branches or pull requests

3 participants