Sendgrid-python: Disable open/click tracking response (round 2)

Created on 11 Jul 2016  路  10Comments  路  Source: sendgrid/sendgrid-python

Issue Summary

Hello!

I'm receiving some odd feedback when I attempt to disable tracking settings for internal test messages. I explicitly set the enable parameter to False, but the response suggests I haven't done so.

Here is the output of print(e.read()):

{"errors":[{"message":"The click_tracking enable parameter is required.","field":"tracking_settings.click_tracking.enable","help":"http://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/errors.html#message.tracking_settings.click_tracking.enable"},{"message":"The open_tracking enable parameter is required.","field":"tracking_settings.open_tracking.enable","help":"http://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/errors.html#message.tracking_settings.open_tracking.enable"},{"message":"The subscription_tracking enable parameter is required.","field":"tracking_settings.subscription_tracking.enable","help":"http://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/errors.html#message.tracking_settings.subscription_tracking.enable"}]}

Here is the relevant section of print(mail.get()):

'tracking_settings': {'subscription_tracking': {}, 'open_tracking': {}, 'click_tracking': {}},

I don't know if this is a bug, or if I'm improperly using the API. Thought I would bring it to your attention.

Thanks!

Steps to Reproduce

My code:

mail = Mail(from_email, subject, to_email, content)

if '@internalemailaddress.com' in email:
        tracking_settings = TrackingSettings()
        tracking_settings.set_click_tracking(ClickTracking(enable=False, False))
        tracking_settings.set_open_tracking(OpenTracking(enable=False))
        tracking_settings.set_subscription_tracking(SubscriptionTracking(enable=False))
        mail.set_tracking_settings(tracking_settings)

Technical details:

  • sendgrid-python Version: master (latest commit: d199afc)
  • Python Version: 3.5
help wanted bug

Most helpful comment

@thinkingserious The tracking_enabled is False . You missed changing the if in one of the helpers

class ClickTracking(object):
    def __init__(self, enable=None, enable_text=None):
        self.enable = enable if enable else None # this line should be if enable != None else None
        self.enable_text = enable_text if enable_text !=None else None

All 10 comments

I've made a workaround that is working for the time being. Helper function:

def disable_tracking(data):

    tracking_disabled = {
        "subscription_tracking" : {"enable" : False},
        "open_tracking" : {"enable" : False},
        "click_tracking" : {"enable" : False}
    }
    data['tracking_settings'] = tracking_disabled

    return data

Where data = mail.get(). Apply after you perform the personalizations using Personalization class, and before you pass to sg.client.mail.send.post(request_body = data).

Hello @inversquare,

I believe you have found a bug similar to https://github.com/sendgrid/sendgrid-go/issues/68

Thanks for sharing your work around before we get it fixed!

Please email us at [email protected] with your T-shirt size and address so that we can send you some swag :)

@inversquare,

This is now fixed with version 3.0.5: https://github.com/sendgrid/sendgrid-python/releases/tag/v3.0.5

Thanks!

I am facing the same issue with sendgrid==3.1.10. The data generated only has enable_text in it and throws the above error. Sample output for reference:

 "tracking_settings": {
    "subscription_tracking": {
      "enable": false
    },
    "open_tracking": {
      "enable": false
    },
    "click_tracking": {
      "enable_text": false
    },
    "ganalytics": {
      "enable": false
    }
  },

Code:

    tracking_settings = TrackingSettings()
    tracking_settings.set_click_tracking(ClickTracking(enable=tracking_enabled, enable_text=tracking_enabled))
    tracking_settings.set_open_tracking(OpenTracking(enable=tracking_enabled))
    tracking_settings.set_subscription_tracking(SubscriptionTracking(enable=False))
    tracking_settings.set_ganalytics(Ganalytics(enable=False))
    mail_obj.set_tracking_settings(tracking_settings)

Thanks for the heads up @kontinuity!

You can follow that bug here: https://github.com/sendgrid/sendgrid-python/issues/202

@kontinuity,

I was unable to reproduce this.

Could you please tell me the value of tracking_enabled in your sample code?

I used tracking_enabled = True

@thinkingserious The tracking_enabled is False . You missed changing the if in one of the helpers

class ClickTracking(object):
    def __init__(self, enable=None, enable_text=None):
        self.enable = enable if enable else None # this line should be if enable != None else None
        self.enable_text = enable_text if enable_text !=None else None

Thanks for the heads up @aaron-maslim! I will take another look.

Just updating that this issue is still present in 3.6.3. But there is a pretty nice workaround using the set_enable() method of the ClickTracking() object. Just do:

tracking_settings = TrackingSettings()
ct = ClickTracking(False, False)
ct.set_enable(False)
tracking_settings.set_click_tracking(ct)
mail.set_tracking_settings(tracking_settings)

Thank you @HUSSTECH!

I've added your vote to this issue to help increase its priority in our backlog queue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bishnusyangja picture bishnusyangja  路  4Comments

danielghurley picture danielghurley  路  4Comments

andriisoldatenko picture andriisoldatenko  路  4Comments

sohamnavadiya picture sohamnavadiya  路  4Comments

thinkingserious picture thinkingserious  路  5Comments