[Django] #23924: EmailMessage type checks should raise TypeError, not AssertionError

27 views
Skip to first unread message

Django

unread,
Nov 26, 2014, 8:51:53 PM11/26/14
to django-...@googlegroups.com
#23924: EmailMessage type checks should raise TypeError, not AssertionError
-----------------------------+--------------------
Reporter: martinblech | Owner: nobody
Type: Bug | Status: new
Component: Core (Mail) | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 1 | UI/UX: 0
-----------------------------+--------------------
If I run the following code:

{{{#!python
email = EmailMessage(
'Subject', 'Content',
'fr...@example.com',
't...@example.com')

print(email.message())
}}}

With the `-O` option, I get:

{{{
Traceback (most recent call last):
File "x.py", line 6, in <module>
't...@example.com')
File "/home/berker/hacking/django/django/core/mail/message.py", line
227, in __init__
assert not isinstance(to, six.string_types), '"to" argument must be a
list or tuple'
AssertionError: "to" argument must be a list or tuple
}}}

But without it, it fails silently and produces a broken `To` header:

{{{
From nobody Wed Nov 26 18:30:08 2014
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Subject: Subject
From: fr...@example.com
To: t, o, @, e, x, a, m, p, l, e, ., c, o, m
Date: Wed, 26 Nov 2014 18:30:08 -0000
Message-ID: <20141126183008.1632.71698@rama>

Content
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/23924>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 26, 2014, 8:57:38 PM11/26/14
to django-...@googlegroups.com
#23924: EmailMessage type checks should raise TypeError, not AssertionError
-----------------------------+------------------------------------

Reporter: martinblech | Owner: nobody
Type: Bug | Status: new
Component: Core (Mail) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-----------------------------+------------------------------------
Changes (by timgraham):

* needs_better_patch: => 0
* stage: Unreviewed => Accepted
* needs_tests: => 0
* needs_docs: => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/23924#comment:1>

Django

unread,
Nov 26, 2014, 9:21:49 PM11/26/14
to django-...@googlegroups.com
#23924: EmailMessage type checks should raise TypeError, not AssertionError
-----------------------------+------------------------------------

Reporter: martinblech | Owner: nobody
Type: Bug | Status: new
Component: Core (Mail) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-----------------------------+------------------------------------

Comment (by martinblech):

[https://github.com/django/django/pull/3630 PR here]

I'm still not sold on the error message, it says `'"to" argument must be a
list or tuple'` but the actual check is `isinstance(to,
six.string_types)`. I think we should change one or the other.

--
Ticket URL: <https://code.djangoproject.com/ticket/23924#comment:2>

Django

unread,
Nov 26, 2014, 9:37:29 PM11/26/14
to django-...@googlegroups.com
#23924: EmailMessage type checks should raise TypeError, not AssertionError
-----------------------------+------------------------------------

Reporter: martinblech | Owner: nobody
Type: Bug | Status: new
Component: Core (Mail) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-----------------------------+------------------------------------
Changes (by martinblech):

* cc: martinblech@… (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/23924#comment:3>

Django

unread,
Nov 27, 2014, 6:44:01 PM11/27/14
to django-...@googlegroups.com
#23924: EmailMessage type checks should raise TypeError, not AssertionError
-----------------------------+------------------------------------
Reporter: martinblech | Owner: nobody
Type: Bug | Status: closed

Component: Core (Mail) | Version: master
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-----------------------------+------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"abf87333a163717308927ad1f230efe45d622c69"]:
{{{
#!CommitTicketReference repository=""
revision="abf87333a163717308927ad1f230efe45d622c69"
Fixed #23924 -- Made EmailMessage raise TypeError for type checks
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/23924#comment:4>

Reply all
Reply to author
Forward
0 new messages