Skip to content

Commit 746cf0e

Browse files
committed
Mandrill: drop Djrill compatibility
1 parent 41754d9 commit 746cf0e

File tree

4 files changed

+18
-390
lines changed

4 files changed

+18
-390
lines changed

CHANGELOG.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ Breaking changes
5050
Be sure to update any dependencies specification (pip install, requirements.txt,
5151
etc.) that had been using ``[amazon_ses]``.
5252

53+
* **Mandrill:** Remove support for Mandrill-specific message attributes left over
54+
from Djrill. These attributes have raised DeprecationWarnings since Anymail 0.3
55+
(in 2016), but are now silently ignored. See
56+
`Migrating from Djrill <https://anymail.dev/en/latest/esps/mandrill/#djrill-message-attributes>`__.
57+
5358
* Require Python 3.7 or later.
5459

5560
* Require urllib3 1.25 or later (released 2019-04-29).

anymail/backends/mandrill.py

Lines changed: 6 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import warnings
21
from datetime import datetime
32

4-
from ..exceptions import AnymailRequestsAPIError, AnymailWarning
3+
from ..exceptions import AnymailRequestsAPIError
54
from ..message import ANYMAIL_STATUSES, AnymailRecipientStatus
6-
from ..utils import combine, get_anymail_setting, last
5+
from ..utils import get_anymail_setting
76
from .base_requests import AnymailRequestsBackend, RequestsPayload
87

98

@@ -60,10 +59,6 @@ def parse_recipient_status(self, response, payload, message):
6059
return recipient_status
6160

6261

63-
class DjrillDeprecationWarning(AnymailWarning, DeprecationWarning):
64-
"""Warning for features carried over from Djrill that will be removed soon"""
65-
66-
6762
def encode_date_for_mandrill(dt):
6863
"""Format a datetime for use as a Mandrill API date field
6964
@@ -107,14 +102,9 @@ def init_payload(self):
107102
}
108103

109104
def set_from_email(self, email):
110-
if getattr(self.message, "use_template_from", False):
111-
self.deprecation_warning(
112-
"message.use_template_from", "message.from_email = None"
113-
)
114-
else:
115-
self.data["message"]["from_email"] = email.addr_spec
116-
if email.display_name:
117-
self.data["message"]["from_name"] = email.display_name
105+
self.data["message"]["from_email"] = email.addr_spec
106+
if email.display_name:
107+
self.data["message"]["from_name"] = email.display_name
118108

119109
def add_recipient(self, recipient_type, email):
120110
assert recipient_type in ["to", "cc", "bcc"]
@@ -125,12 +115,7 @@ def add_recipient(self, recipient_type, email):
125115
to_list.append(recipient_data)
126116

127117
def set_subject(self, subject):
128-
if getattr(self.message, "use_template_subject", False):
129-
self.deprecation_warning(
130-
"message.use_template_subject", "message.subject = None"
131-
)
132-
else:
133-
self.data["message"]["subject"] = subject
118+
self.data["message"]["subject"] = subject
134119

135120
def set_reply_to(self, emails):
136121
if emails:
@@ -259,109 +244,3 @@ def process_esp_extra(self):
259244
self.data["message"].update(esp_extra["message"])
260245
except KeyError:
261246
pass
262-
263-
# Djrill deprecated message attrs
264-
265-
def deprecation_warning(self, feature, replacement=None):
266-
msg = "Djrill's `%s` will be removed in an upcoming Anymail release." % feature
267-
if replacement:
268-
msg += " Use `%s` instead." % replacement
269-
warnings.warn(msg, DjrillDeprecationWarning)
270-
271-
def deprecated_to_esp_extra(self, attr, in_message_dict=False):
272-
feature = "message.%s" % attr
273-
if in_message_dict:
274-
replacement = "message.esp_extra = {'message': {'%s': <value>}}" % attr
275-
else:
276-
replacement = "message.esp_extra = {'%s': <value>}" % attr
277-
self.deprecation_warning(feature, replacement)
278-
279-
esp_message_attrs = (
280-
("async", last, None),
281-
("ip_pool", last, None),
282-
("from_name", last, None), # overrides display name parsed from from_email
283-
("important", last, None),
284-
("auto_text", last, None),
285-
("auto_html", last, None),
286-
("inline_css", last, None),
287-
("url_strip_qs", last, None),
288-
("tracking_domain", last, None),
289-
("signing_domain", last, None),
290-
("return_path_domain", last, None),
291-
("merge_language", last, None),
292-
("preserve_recipients", last, None),
293-
("view_content_link", last, None),
294-
("subaccount", last, None),
295-
("google_analytics_domains", last, None),
296-
("google_analytics_campaign", last, None),
297-
("global_merge_vars", combine, None),
298-
("merge_vars", combine, None),
299-
("recipient_metadata", combine, None),
300-
("template_name", last, None),
301-
("template_content", combine, None),
302-
)
303-
304-
def set_async(self, is_async):
305-
self.deprecated_to_esp_extra("async")
306-
self.esp_extra["async"] = is_async
307-
308-
def set_ip_pool(self, ip_pool):
309-
self.deprecated_to_esp_extra("ip_pool")
310-
self.esp_extra["ip_pool"] = ip_pool
311-
312-
def set_global_merge_vars(self, global_merge_vars):
313-
self.deprecation_warning(
314-
"message.global_merge_vars", "message.merge_global_data"
315-
)
316-
self.set_merge_global_data(global_merge_vars)
317-
318-
def set_merge_vars(self, merge_vars):
319-
self.deprecation_warning("message.merge_vars", "message.merge_data")
320-
self.set_merge_data(merge_vars)
321-
322-
def set_return_path_domain(self, domain):
323-
self.deprecation_warning(
324-
"message.return_path_domain", "message.envelope_sender"
325-
)
326-
self.esp_extra.setdefault("message", {})["return_path_domain"] = domain
327-
328-
def set_template_name(self, template_name):
329-
self.deprecation_warning("message.template_name", "message.template_id")
330-
self.set_template_id(template_name)
331-
332-
def set_template_content(self, template_content):
333-
self.deprecated_to_esp_extra("template_content")
334-
self.esp_extra["template_content"] = template_content
335-
336-
def set_recipient_metadata(self, recipient_metadata):
337-
self.deprecated_to_esp_extra("recipient_metadata", in_message_dict=True)
338-
self.esp_extra.setdefault("message", {})[
339-
"recipient_metadata"
340-
] = recipient_metadata
341-
342-
# Set up simple set_<attr> functions for any missing esp_message_attrs attrs
343-
# (avoids dozens of simple `self.data["message"][<attr>] = value` functions)
344-
345-
@classmethod
346-
def define_message_attr_setters(cls):
347-
for attr, _, _ in cls.esp_message_attrs:
348-
setter_name = "set_%s" % attr
349-
try:
350-
getattr(cls, setter_name)
351-
except AttributeError:
352-
setter = cls.make_setter(attr, setter_name)
353-
setattr(cls, setter_name, setter)
354-
355-
@staticmethod
356-
def make_setter(attr, setter_name):
357-
# sure wish we could use functools.partial
358-
# to create instance methods (descriptors)
359-
def setter(self, value):
360-
self.deprecated_to_esp_extra(attr, in_message_dict=True)
361-
self.esp_extra.setdefault("message", {})[attr] = value
362-
363-
setter.__name__ = setter_name
364-
return setter
365-
366-
367-
MandrillPayload.define_message_attr_setters()

docs/esps/mandrill.rst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,16 +383,19 @@ Changes to EmailMessage attributes
383383
instead. You'll need to pass a valid email address (not just a domain),
384384
but Anymail will use only the domain, and will ignore anything before the @.
385385

386+
.. _djrill-message-attributes:
387+
386388
**Other Mandrill-specific attributes**
387389
Djrill allowed nearly all Mandrill API parameters to be set
388390
as attributes directly on an EmailMessage. With Anymail, you
389391
should instead set these in the message's
390392
:ref:`esp_extra <mandrill-esp-extra>` dict as described above.
391393

392-
Although the Djrill style attributes are still supported (for now),
393-
Anymail will issue a :exc:`DeprecationWarning` if you try to use them.
394-
These warnings are visible during tests (with Django's default test
395-
runner), and will explain how to update your code.
394+
.. versionchanged:: 10.0
395+
396+
These Djrill-specific attributes are no longer supported,
397+
and will be silently ignored. (Earlier versions raised a
398+
:exc:`DeprecationWarning` but still worked.)
396399

397400
You can also use the following git grep expression to find potential
398401
problems:

0 commit comments

Comments
 (0)