#36894: Email fail_silently, auth_user, auth_password are ignored when 
connection
param provided
-------------------------------------+-------------------------------------
     Reporter:  Mike Edmunds         |                    Owner:  Kundan
         Type:                       |  Yadav
  Cleanup/optimization               |                   Status:  assigned
    Component:  Core (Mail)          |                  Version:  6.0
     Severity:  Normal               |               Resolution:
     Keywords:  email fail_silently  |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  1                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Mike Edmunds):

 * easy:  0 => 1


Old description:

> Most django.core.mail APIs take a `fail_silently` parameter which is
> intended to suppress errors during sending, as well as a `connection`
> parameter to provide a specific EmailBackend instance for sending. When
> `connection` is specified, `fail_silently` is ignored.
>
> To reproduce, configure your email settings to cause an error (e.g.,
> `EMAIL_HOST="not.a.real.host"`) and:
> {{{#!python
> from django.core.mail import get_connection, send_mail
>
> send_mail("subject", "body", None, ["[email protected]"])
> # Correct behavior: raises socket.gaierror: [Errno 8] nodename nor
> servname provided, or not known
>
> send_mail("subject", "body", None, ["[email protected]"],
> fail_silently=True)
> # Correct behavior: returns 0 messages sent, doesn't raise an error
>
> send_mail("subject", "body", None, ["[email protected]"],
> fail_silently=True, connection=get_connection())
> # Bug: despite fail_silently=True, raises socket.gaierror
> }}}
>
> A similar problem exists with the `auth_user` and `auth_password` params
> to `send_mail()` and `send_mass_mail()`, which are also silently ignored
> when a `connection` is provided.
>
> There is no safe way to set any of these options on a connection
> (EmailBackend instance) once it has been constructed. The correct way to
> achieve the desired behavior is move `fail_silently` and the other params
> into `get_connection()`:
>
> {{{#!python
> send_mail("subject", "body", None, ["[email protected]"],
>     connection=get_connection(fail_silently=True, username="auth_user",
> password="auth_password"))
> }}}
>

> **Suggested fix**
>
> Django's email APIs should handle `fail_silently`, `auth_user` and
> `auth_password` params as an error when `connection` is also provided.
> This will involve:
> - Changing the default from `fail_silently=False` to `fail_silently=None`
> to be able to distinguish the cases. (Don't forget EmailMessage.send().)
> - Raising a TypeError when `connection is not None and fail_silently is
> not None`. Something like "fail_silently cannot be used with a
> connection. (Pass fail_silently to get_connection() instead.)"
> - Converting fail_silently==None to False where the high level APIs call
> get_connection()
> - Issuing similar error messages for `auth_user` and `auth_password`
> (which already default to None)
> - Updating tests to cover the new behavior

New description:

 Most django.core.mail APIs take a `fail_silently` parameter which is
 intended to suppress errors during sending, as well as a `connection`
 parameter to provide a specific EmailBackend instance for sending. When
 `connection` is specified, `fail_silently` is ignored.

 To reproduce, configure your email settings to cause an error (e.g.,
 `EMAIL_HOST="not.a.real.host"`) and:
 {{{#!python
 from django.core.mail import get_connection, send_mail

 send_mail("subject", "body", None, ["[email protected]"])
 # Correct behavior: raises socket.gaierror: [Errno 8] nodename nor
 servname provided, or not known

 send_mail("subject", "body", None, ["[email protected]"], fail_silently=True)
 # Correct behavior: returns 0 messages sent, doesn't raise an error

 send_mail("subject", "body", None, ["[email protected]"], fail_silently=True,
 connection=get_connection())
 # Bug: despite fail_silently=True, raises socket.gaierror
 }}}

 A similar problem exists with the `auth_user` and `auth_password` params
 to `send_mail()` and `send_mass_mail()`, which are also silently ignored
 when a `connection` is provided.

 There is no safe way to set any of these options on a connection
 (EmailBackend instance) once it has been constructed. The correct way to
 achieve the desired behavior is move `fail_silently` and the other params
 into `get_connection()`:

 {{{#!python
 send_mail("subject", "body", None, ["[email protected]"],
     connection=get_connection(fail_silently=True, username="auth_user",
 password="auth_password"))
 }}}


 **Suggested fix**

 Django's email APIs should handle `fail_silently`, `auth_user` and
 `auth_password` params as an error when `connection` is also provided.
 This will involve:
 - Changing the default from `fail_silently=False` to `fail_silently=None`
 to be able to distinguish the cases. (Don't forget EmailMessage.send().)
 - Raising a TypeError when `connection is not None and fail_silently is
 not None`. Something like "fail_silently cannot be used with a connection.
 (Pass fail_silently to get_connection() instead.)"
 - Converting fail_silently==None to False where the high level APIs call
 get_connection()
 - Issuing similar error messages for `auth_user` and `auth_password`
 (which already default to None)
 - Updating tests to cover the new behavior
 - Updating docs to note the changed behavior (params that had been
 silently ignored with `connection` will now raise an error)

--
Comment:

 (Edited "suggested fix" to include adding versionchanged notes in relevant
 docs.)
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36894#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019c1ff7840b-36b2a7bf-0200-4609-a102-b7ac5dab8fc3-000000%40eu-central-1.amazonses.com.

Reply via email to