AnymailMessage: initialize anymail_status to empty AnymailStatus

Allows clients that use AnymailMessage or AnymailMessageMixin
to access (e.g.) message.anymail_status.message_id without
an AttributeError, even when using a non-Anymail backend
(e.g., during testing).

Also clarify docs of anymail_status attribute to note it only gets
attached to a normal Django EmailMessage when sent through
an Anymail backend.

(May help with situation described in #36)
This commit is contained in:
medmunds
2016-10-20 11:50:31 -07:00
parent a1380b82f3
commit 60dc11559d
2 changed files with 18 additions and 1 deletions

View File

@@ -28,7 +28,7 @@ class AnymailMessageMixin(object):
self.template_id = kwargs.pop('template_id', UNSET)
self.merge_data = kwargs.pop('merge_data', UNSET)
self.merge_global_data = kwargs.pop('merge_global_data', UNSET)
self.anymail_status = None
self.anymail_status = AnymailStatus()
# noinspection PyArgumentList
super(AnymailMessageMixin, self).__init__(*args, **kwargs)