Opened 14 years ago

Closed 13 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: dev
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: no

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 14 years ago.
email-recipients-tuple-fix-1.2-beta-SVN-12755.diff (515 bytes ) - added by Ben Davis 14 years ago.
Updated for 1.2-beta
11928-test.diff (1.1 KB ) - added by Claude Paroz 13 years ago.
Test that problem has been resolved

Download all attachments as: .zip

Change History (9)

by Ben Davis, 14 years ago

comment:1 by Ben Davis, 14 years ago

Owner: changed from nobody to Ben Davis
Status: newassigned

comment:2 by Chris Beaven, 14 years ago

Needs tests: set
Triage Stage: UnreviewedAccepted

by Ben Davis, 14 years ago

Updated for 1.2-beta

comment:3 by Julien Phalip, 13 years ago

Severity: Normal
Type: Bug

by Claude Paroz, 13 years ago

Attachment: 11928-test.diff added

Test that problem has been resolved

comment:4 by Claude Paroz, 13 years ago

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 by Jannis Leidel, 13 years ago

Triage Stage: AcceptedReady for checkin

comment:6 by Jannis Leidel, 13 years ago

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