[Django] #34732: UnicodeEncodeError on two tests in Python 3.12

9 views
Skip to first unread message

Django

unread,
Jul 21, 2023, 3:32:10 PM7/21/23
to django-...@googlegroups.com
#34732: UnicodeEncodeError on two tests in Python 3.12
--------------------------------------------------+------------------------
Reporter: Michel Alexandre Salim | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: dev
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
--------------------------------------------------+------------------------
When running the tests inside a virtual environment with Fedora 39's
python3-3.12.0~b4-1.fc39.x86_64, there are currently two test failures
left with the `test_sqlite` backend


{{{
======================================================================
ERROR: test_safe_mime_multipart
(mail.tests.MailTests.test_safe_mime_multipart)
Make sure headers can be set with a different encoding than utf-8 in
----------------------------------------------------------------------
Traceback (most recent call last):
File
"/home/michel/src/github/django/django/django/core/mail/message.py", line
64, in forbid_multi_line_headers
val.encode("ascii")
UnicodeEncodeError: 'ascii' codec can't encode character '\xfc' in
position 2: ordinal not in range(128)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/michel/src/github/django/django/tests/mail/tests.py", line
504, in test_safe_mime_multipart
msg.message()["To"],
^^^^^^^^^^^^^
File
"/home/michel/src/github/django/django/django/core/mail/message.py", line
266, in message
self._set_list_header_if_not_empty(msg, "To", self.to)
File
"/home/michel/src/github/django/django/django/core/mail/message.py", line
431, in _set_list_header_if_not_empty
msg[header] = value
~~~^^^^^^^^
File
"/home/michel/src/github/django/django/django/core/mail/message.py", line
188, in __setitem__
name, val = forbid_multi_line_headers(name, val, self.encoding)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File
"/home/michel/src/github/django/django/django/core/mail/message.py", line
67, in forbid_multi_line_headers
val = ", ".join(
^^^^^^^^^^
File
"/home/michel/src/github/django/django/django/core/mail/message.py", line
68, in <genexpr>
sanitize_address(addr, encoding) for addr in getaddresses((val,))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File
"/home/michel/src/github/django/django/django/core/mail/message.py", line
101, in sanitize_address
raise ValueError(f'Invalid address "{address}"')
ValueError: Invalid address ""

======================================================================
ERROR: test_unicode_address_header
(mail.tests.MailTests.test_unicode_address_header)
Regression for #11144 - When a to/from/cc header contains Unicode,
----------------------------------------------------------------------
Traceback (most recent call last):
File
"/home/michel/src/github/django/django/django/core/mail/message.py", line
64, in forbid_multi_line_headers
val.encode("ascii")
UnicodeEncodeError: 'ascii' codec can't encode character '\xfc' in
position 2: ordinal not in range(128)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/michel/src/github/django/django/tests/mail/tests.py", line
461, in test_unicode_address_header
email.message()["To"],
^^^^^^^^^^^^^^^
File
"/home/michel/src/github/django/django/django/core/mail/message.py", line
266, in message
self._set_list_header_if_not_empty(msg, "To", self.to)
File
"/home/michel/src/github/django/django/django/core/mail/message.py", line
431, in _set_list_header_if_not_empty
msg[header] = value
~~~^^^^^^^^
File
"/home/michel/src/github/django/django/django/core/mail/message.py", line
165, in __setitem__
name, val = forbid_multi_line_headers(name, val, self.encoding)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File
"/home/michel/src/github/django/django/django/core/mail/message.py", line
67, in forbid_multi_line_headers
val = ", ".join(
^^^^^^^^^^
File
"/home/michel/src/github/django/django/django/core/mail/message.py", line
68, in <genexpr>
sanitize_address(addr, encoding) for addr in getaddresses((val,))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File
"/home/michel/src/github/django/django/django/core/mail/message.py", line
101, in sanitize_address
raise ValueError(f'Invalid address "{address}"')
ValueError: Invalid address ""

}}}

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

Django

unread,
Jul 21, 2023, 3:36:16 PM7/21/23
to django-...@googlegroups.com
#34732: UnicodeEncodeError on two tests in Python 3.12
-------------------------------------+-------------------------------------
Reporter: Michel Alexandre | Owner: nobody
Salim |
Type: Uncategorized | Status: closed
Component: Uncategorized | Version: dev
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

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


Comment:

This not an issue in Django, but a regression in Python 3.12.0b4, check
out https://github.com/python/cpython/issues/106669.

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

Django

unread,
Jul 21, 2023, 3:46:14 PM7/21/23
to django-...@googlegroups.com
#34732: UnicodeEncodeError on two tests in Python 3.12
-------------------------------------+-------------------------------------
Reporter: Michel Alexandre | Owner: nobody
Salim |
Type: Uncategorized | Status: closed
Component: Uncategorized | Version: dev
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Michel Alexandre Salim):

Thanks! Yeah, I was just debugging with breakpoint() and realized it's
getaddresses that now returns `[('', '')]` as you noted

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

Reply all
Reply to author
Forward
0 new messages