#35361 closed Bug (fixed)
SafeMIMEText.set_payload() crash on Python 3.11.9
Reported by: | Sarah Boyce | Owned by: | Natalia Bidart |
---|---|---|---|
Component: | Core (Mail) | Version: | 4.2 |
Severity: | Release blocker | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
A recent bug fix to Python gh-76511 has been back ported to Python 3.11 and 3.12.
See the release notes of Python 3.11.9 and the soon to be released Python 3.12.3.
As part of the work to prepare Django for Python 3.13, a fix for this has already been merged to main in b231bcd19e57267ce1fc21d42d46f0b65fdcfcf8.
Believe this needs to be back ported to Django 4.2 and Django 5.0 to support the latest (or soon to be latest) Python 3.11 and Python 3.12 versions.
Confirmed when testing Django 4.2 against Python 3.11.9, we know have the following test failure:
====================================================================== ERROR [0.034s]: test_dont_base64_encode (tests.mail.tests.MailTests.test_dont_base64_encode) ---------------------------------------------------------------------- Traceback (most recent call last): File "/tests/django/tests/mail/tests.py", line 902, in test_dont_base64_encode s = msg.message().as_string() ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tests/django/django/core/mail/message.py", line 133, in as_string g.flatten(self, unixfrom=unixfrom, linesep=linesep) File "/usr/local/lib/python3.11/email/generator.py", line 115, in flatten self._write(msg) File "/usr/local/lib/python3.11/email/generator.py", line 180, in _write self._dispatch(msg) File "/usr/local/lib/python3.11/email/generator.py", line 217, in _dispatch meth(msg) File "/usr/local/lib/python3.11/email/generator.py", line 246, in _handle_text msg.set_payload(msg._payload, charset) File "/tests/django/django/core/mail/message.py", line 168, in set_payload has_long_lines = any( ^^^^ File "/tests/django/django/core/mail/message.py", line 169, in <genexpr> len(line.encode()) > RFC5322_EMAIL_LINE_LENGTH_LIMIT ^^^^^^^^^^^^^ UnicodeEncodeError: 'utf-8' codec can't encode characters in position 28-33: surrogates not allowed
Change History (12)
comment:1 by , 8 months ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 8 months ago
Has patch: | set |
---|---|
Owner: | changed from | to
Status: | new → assigned |
PR for main adding a test (to be backported along with the fix from b231bcd19e57267ce1fc21d42d46f0b65fdcfcf8):
https://github.com/django/django/pull/18057/
comment:12 by , 8 months ago
A disadvantage of the current May 6 schedule for the release with these Python 3.11.9 and 3.12.3 compatibility fixes is that Ubuntu 24.04 LTS will be releasing with Python 3.12.3 on April 25.
Related forum discussion: https://forum.djangoproject.com/t/send-mail-throws-unicodeencodeerror-under-python-3-11-9/29871/3