Opened 7 years ago

Closed 5 years ago

#11928 closed Cleanup/optimization (fixed)

EmailMessage.to accepts tuple or list, but EmailMessage.recipients() fails if it's a tuple

Reported by: Ben Davis Owned by: Ben Davis
Component: Core (Mail) Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX:

Description

Basically, if you set "to" to a tuple, the recipients() method fails because it's concatenating self.to + self.bcc, and bcc by default is []. So if self.to is a tuple, you get an exception. The simple fix is:

Index: django/core/mail.py
===================================================================
--- django/core/mail.py (revision 11587)
+++ django/core/mail.py (working copy)
@@ -255,7 +255,7 @@
         Returns a list of all recipients of the email (includes direct
         addressees as well as Bcc entries).
         """
-        return self.to + self.bcc
+        return list(self.to) + list(self.bcc)

     def send(self, fail_silently=False):
         """Sends the email message."""

Attachments (3)

email-recipients-tuple-fix.diff (491 bytes) - added by Ben Davis 7 years ago.
email-recipients-tuple-fix-1.2-beta-SVN-12755.diff (515 bytes) - added by Ben Davis 7 years ago.
Updated for 1.2-beta
11928-test.diff (1.1 KB) - added by Claude Paroz 5 years ago.
Test that problem has been resolved

Download all attachments as: .zip

Change History (9)

Changed 7 years ago by Ben Davis

comment:1 Changed 7 years ago by Ben Davis

Needs documentation: unset
Needs tests: unset
Owner: changed from nobody to Ben Davis
Patch needs improvement: unset
Status: newassigned

comment:2 Changed 7 years ago by Chris Beaven

Needs tests: set
Triage Stage: UnreviewedAccepted

Changed 7 years ago by Ben Davis

Updated for 1.2-beta

comment:3 Changed 5 years ago by Julien Phalip

Severity: Normal
Type: Bug

Changed 5 years ago by Claude Paroz

Attachment: 11928-test.diff added

Test that problem has been resolved

comment:4 Changed 5 years ago by Claude Paroz

Easy pickings: unset
Keywords: mail to tuple removed
Needs tests: unset
Type: BugCleanup/optimization

I think that the problem has been fixed by other changesets. However, I still attach a test case with recipients as tuples, as I think it was still untested.

comment:5 Changed 5 years ago by Jannis Leidel

Triage Stage: AcceptedReady for checkin

comment:6 Changed 5 years ago by Jannis Leidel

Resolution: fixed
Status: assignedclosed

In [16133]:

Fixed #11928 -- Added test for tuple to list conversion during mail message initialization added in r11709. Thanks, Claude Paroz.

Note: See TracTickets for help on using tickets.
Back to Top