From bf6d3fff5197006c4c872566d172f8f187de7ba7 Mon Sep 17 00:00:00 2001 From: Craig Silverstein Date: Fri, 26 May 2017 10:44:33 -0700 Subject: [PATCH] Set headers early in the constructor, rather than late. `self.set_replyto()` can call `set.set_headers()`, but we were calling `set_replyto()` in `__init__` before we did `self.headers = {}`. So `set_replyto` was failing with `self.headers not defined`. This should fix that. I'd like to upgrade the sendgrid library instead, since the latest version has totally refactored how the Mail class is used. But that would require changing from SendGridClient to SendGridAPIClient -- the former has gone away in latest versions of the sendgrid lib -- and that's a scary (though worthwhile) change. Auditors: kevindangoor Test plan: I ran python -c "import third_party.sendgrid as s; s.Mail(reply_to='FooBar ')" This failed with `'Mail' object has no attribute 'headers'` before my change, but passed after. --- sendgrid/message.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sendgrid/message.py b/sendgrid/message.py index 18be5172a..3bb3a3dbe 100644 --- a/sendgrid/message.py +++ b/sendgrid/message.py @@ -30,6 +30,8 @@ def __init__(self, **opts): headers: Set headers files: Attachments """ + self.headers = {} + self.set_headers(opts.get('headers', {})) self.to = [] self.to_name = [] self.cc = [] @@ -46,8 +48,6 @@ def __init__(self, **opts): self.reply_to = '' self.set_replyto(opts.get('reply_to', '')) self.files = opts.get('files', {}) - self.headers = {} - self.set_headers(opts.get('headers', {})) self.date = opts.get('date', rfc822.formatdate()) self.content = opts.get('content', {}) self.smtpapi = opts.get('smtpapi', SMTPAPIHeader())