Opened 10 years ago
Closed 10 years ago
#23924 closed Bug (fixed)
EmailMessage type checks should raise TypeError, not AssertionError
Reported by: | Martín Blech | Owned by: | nobody |
---|---|---|---|
Component: | Core (Mail) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | martinblech@… | Triage Stage: | Accepted |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
If I run the following code:
email = EmailMessage( 'Subject', 'Content', 'from@example.com', 'to@example.com') print(email.message())
With the -O
option, I get:
Traceback (most recent call last): File "x.py", line 6, in <module> 'to@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: from@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
Change History (4)
comment:1 by , 10 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 10 years ago
comment:3 by , 10 years ago
Cc: | added |
---|
comment:4 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
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 isisinstance(to, six.string_types)
. I think we should change one or the other.