Internal: validate AnymailRecipientStatus at init

Catch invalid message_id and status when initializing
AnymailRecipientStatus, so problems with ESP response
are caught earlier (in individual backend
parse_recipient_status, rather than base backend _send).
This commit is contained in:
medmunds
2021-01-25 10:45:39 -08:00
committed by Mike Edmunds
parent 3e0056fa2f
commit fb5912f0e7
3 changed files with 18 additions and 0 deletions

View File

@@ -85,6 +85,14 @@ class AnymailRecipientStatus:
"""Information about an EmailMessage's send status for a single recipient"""
def __init__(self, message_id, status):
try:
# message_id must be something that can be put in a set
# (see AnymailStatus.set_recipient_status)
set([message_id])
except TypeError:
raise TypeError("Invalid message_id %r is not scalar type" % message_id)
if status is not None and status not in ANYMAIL_STATUSES:
raise ValueError("Invalid status %r" % status)
self.message_id = message_id # ESP message id
self.status = status # one of ANYMAIL_STATUSES, or None for not yet sent to ESP