Django 1.7: inconsistent behaviour of the fail_silently option when using SMTP backend

186 views
Skip to first unread message

Marcin Nowak

unread,
Sep 28, 2014, 7:26:42 AM9/28/14
to django-d...@googlegroups.com
Hello,

After sereral minutes while using new Django (1.7) in DEBUG mode, I've got enigmatic error on the screen: "A server error occurred. Please contact the administrator."
This message is shown when another exception is raised within django.core.handlers.base.handle_uncaught_exception.
What exception was raised inside uncaught exception handler? socket.error. Why? Django tried to send me an email using nonexistent smtp (localhost:25, the default). 

AdminEmailHandler is sending emails with fail_silently set to True, but the django.core.mail.smtp backend does not respect this setting as expected. Any connection problem will generate "A server error occured[...]" screen instead of traceback or error 500 page. This issue was created by resolving https://code.djangoproject.com/ticket/21189 

"Fail silently" mode with SMTP backend is not 100% silent anymore. I saw that docs were changed, but the behaviour is inconsistent now. As a developer I'm expecting to silence ANY email error, including connection errors (not only SMTP errors). As an application developer I have no idea which email backend will be used, so I can't wrap every "mail.send()" with additional try-except block catching all possible exceptions. When I need to silent sending email fail, the email backend should do it for me (as before v1.7).

Line https://github.com/django/django/blob/stable/1.7.x/django/core/mail/backends/smtp.py#L61 should catch socket.error too, or should be reverted to previous state.

Kind Regards,
Marcin

Florian Apolloner

unread,
Sep 28, 2014, 11:35:31 AM9/28/14
to django-d...@googlegroups.com
Hi Marcin,

can you please open a ticket for this? If you are up to it, a patch with tests would be superb!

Thanks,
Florian

Marcin Nowak

unread,
Sep 28, 2014, 3:58:02 PM9/28/14
to django-d...@googlegroups.com
Ok, I'll do it tomorrow.
Reply all
Reply to author
Forward
0 new messages