Django

Code

Ticket #7574 (closed: fixed)

Opened 5 months ago

Last modified 4 months ago

EmailMultiAlternatives and send_email do not handle ugettext_lazy translated strings correctly

Reported by: gary.hutspot@gmail.com Assigned to: mk
Milestone: Component: django.core.mail
Version: SVN Keywords:
Cc: gary.hutspot@gmail.com Triage Stage: Ready for checkin
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

When trying to send email with a subject that is lazily translated, the following TypeError? is thrown:

argument of type 'proxy' is not iterable

Cut and paste compatible example:

from django.utils.translation import ugettext_lazy as _
from django.core.mail import send_mail
from django.conf import settings

# If you do not have smtp running on your local system, specify your smtp server here
settings.configure(EMAIL_HOST='your.smtp.server')

send_mail(_('Subject here'), 'Here is the message.', 'from@example.com', ['to@example.com'], fail_silently=False)

Produces:

$ python proof.py 
Traceback (most recent call last):
  File "proof.py", line 8, in <module>
    fail_silently=False)
  File "/usr/lib/python2.5/site-packages/django/core/mail.py", line 333, in send_mail
    connection=connection).send()
  File "/usr/lib/python2.5/site-packages/django/core/mail.py", line 259, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/usr/lib/python2.5/site-packages/django/core/mail.py", line 168, in send_messages
    sent = self._send(message)
  File "/usr/lib/python2.5/site-packages/django/core/mail.py", line 182, in _send
    email_message.message().as_string())
  File "/usr/lib/python2.5/site-packages/django/core/mail.py", line 241, in message
    msg['Subject'] = self.subject
  File "/usr/lib/python2.5/site-packages/django/core/mail.py", line 92, in __setitem__
    name, val = forbid_multi_line_headers(name, val)
  File "/usr/lib/python2.5/site-packages/django/core/mail.py", line 74, in forbid_multi_line_headers
    if '\n' in val or '\r' in val:
TypeError: argument of type '__proxy__' is not iterable

Attachments

7574.patch (0.9 kB) - added by mk on 07/24/08 10:14:08.

Change History

07/01/08 03:50:19 changed by erl

  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

I am having the same problem. Currently I use ugettext instead of ugettext_lazy as a workaround.

07/24/08 10:14:08 changed by mk

  • attachment 7574.patch added.

07/24/08 10:16:44 changed by mk

  • has_patch set to 1.
  • stage changed from Unreviewed to Ready for checkin.

Just changing the order of the force_unicode block and the \n/\r detection block is enough.

07/24/08 10:16:55 changed by mk

  • owner changed from nobody to mk.
  • status changed from new to assigned.

07/25/08 22:36:21 changed by mtredinnick

Since Header instances don't act as containers or sequences (they don't support in tests), this patch cannot work. Writing as test for the failing case might have helped detect that.

(Thanks for taking the time to write a patch, but please let somebody else triage it to "ready for checkin" so that we get another set of eyes on that patch for review.)

07/25/08 22:37:28 changed by mtredinnick

  • status changed from assigned to closed.
  • resolution set to fixed.

(In [8083]) Fixed #7574 -- Fixed the handling of lazy translation in email headers.


Add/Change #7574 (EmailMultiAlternatives and send_email do not handle ugettext_lazy translated strings correctly)




Change Properties
Action