Opened 6 years ago

Closed 4 years ago

#11928 closed Cleanup/optimization (fixed)

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

Reported by: bendavis78 Owned by: bendavis78
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 bendavis78 6 years ago.
email-recipients-tuple-fix-1.2-beta-SVN-12755.diff (515 bytes) - added by bendavis78 5 years ago.
Updated for 1.2-beta
11928-test.diff (1.1 KB) - added by claudep 4 years ago.
Test that problem has been resolved

Download all attachments as: .zip

Change History (9)

Changed 6 years ago by bendavis78

comment:1 Changed 6 years ago by bendavis78

  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to bendavis78
  • Patch needs improvement unset
  • Status changed from new to assigned

comment:2 Changed 6 years ago by SmileyChris

  • Needs tests set
  • Triage Stage changed from Unreviewed to Accepted

Changed 5 years ago by bendavis78

Updated for 1.2-beta

comment:3 Changed 4 years ago by julien

  • Severity set to Normal
  • Type set to Bug

Changed 4 years ago by claudep

Test that problem has been resolved

comment:4 Changed 4 years ago by claudep

  • Easy pickings unset
  • Keywords mail to tuple removed
  • Needs tests unset
  • Type changed from Bug to Cleanup/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 4 years ago by jezdez

  • Triage Stage changed from Accepted to Ready for checkin

comment:6 Changed 4 years ago by jezdez

  • Resolution set to fixed
  • Status changed from assigned to closed

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