[Django] #35630: `django.utils.formats.sanitize_strftime_format()` no longer works correctly with Python 3.13.0b4

33 views
Skip to first unread message

Django

unread,
Jul 25, 2024, 6:46:02 AM7/25/24
to django-...@googlegroups.com
#35630: `django.utils.formats.sanitize_strftime_format()` no longer works correctly
with Python 3.13.0b4
------------------------------+--------------------------------------
Reporter: Michał Górny | Type: Bug
Status: new | Component: Utilities
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
------------------------------+--------------------------------------
Python 3.13.0b4 includes a change to
[https://github.com/python/cpython/issues/120713 add zero-padding to `%y`
and `%Y` `strftime()` formats]. However, padding is not added to `%C` or
`%F` formats.

The current logic in django assumes that if `%Y` is padded, then no
padding needs to be added:

{{{
if datetime.date(1, 1, 1).strftime("%Y") == "0001":
return fmt
}}}
https://github.com/django/django/blob/0e94f292cda632153f2b3d9a9037eb0141ae9c2e/django/utils/formats.py#L266

This misfires on 3.13.0b4, stopping django from adding the padding to `%C`
and `%F` formats.

I've filed [https://github.com/python/cpython/issues/122272 a bug to
CPython upstream about this inconsistent behavior].

This is causing the following test failures:

{{{
======================================================================
FAIL: test_sanitize_strftime_format
(i18n.tests.FormattingTests.test_sanitize_strftime_format) (year=1,
fmt='%C')
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/django/tests/i18n/tests.py", line 1195, in
test_sanitize_strftime_format
self.assertEqual(dt.strftime(fmt), expected)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: '0' != '00'
- 0
+ 00
? +


======================================================================
FAIL: test_sanitize_strftime_format
(i18n.tests.FormattingTests.test_sanitize_strftime_format) (year=1,
fmt='%F')
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/django/tests/i18n/tests.py", line 1195, in
test_sanitize_strftime_format
self.assertEqual(dt.strftime(fmt), expected)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: '1-01-01' != '0001-01-01'
- 1-01-01
+ 0001-01-01
? +++


======================================================================
FAIL: test_sanitize_strftime_format
(i18n.tests.FormattingTests.test_sanitize_strftime_format) (year=99,
fmt='%C')
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/django/tests/i18n/tests.py", line 1195, in
test_sanitize_strftime_format
self.assertEqual(dt.strftime(fmt), expected)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: '0' != '00'
- 0
+ 00
? +


======================================================================
FAIL: test_sanitize_strftime_format
(i18n.tests.FormattingTests.test_sanitize_strftime_format) (year=99,
fmt='%F')
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/django/tests/i18n/tests.py", line 1195, in
test_sanitize_strftime_format
self.assertEqual(dt.strftime(fmt), expected)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: '99-01-01' != '0099-01-01'
- 99-01-01
+ 0099-01-01
? ++


======================================================================
FAIL: test_sanitize_strftime_format
(i18n.tests.FormattingTests.test_sanitize_strftime_format) (year=999,
fmt='%C')
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/django/tests/i18n/tests.py", line 1195, in
test_sanitize_strftime_format
self.assertEqual(dt.strftime(fmt), expected)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: '9' != '09'
- 9
+ 09
? +


======================================================================
FAIL: test_sanitize_strftime_format
(i18n.tests.FormattingTests.test_sanitize_strftime_format) (year=999,
fmt='%F')
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/django/tests/i18n/tests.py", line 1195, in
test_sanitize_strftime_format
self.assertEqual(dt.strftime(fmt), expected)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: '999-01-01' != '0999-01-01'
- 999-01-01
+ 0999-01-01
? +


======================================================================
FAIL: test_sanitize_strftime_format_with_escaped_percent
(i18n.tests.FormattingTests.test_sanitize_strftime_format_with_escaped_percent)
(year=1, fmt='%%%C')
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/django/tests/i18n/tests.py", line 1227, in
test_sanitize_strftime_format_with_escaped_percent
self.assertEqual(dt.strftime(fmt), expected)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: '%0' != '%00'
- %0
+ %00
? +


======================================================================
FAIL: test_sanitize_strftime_format_with_escaped_percent
(i18n.tests.FormattingTests.test_sanitize_strftime_format_with_escaped_percent)
(year=1, fmt='%%%F')
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/django/tests/i18n/tests.py", line 1227, in
test_sanitize_strftime_format_with_escaped_percent
self.assertEqual(dt.strftime(fmt), expected)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: '%1-01-01' != '%0001-01-01'
- %1-01-01
+ %0001-01-01
? +++


======================================================================
FAIL: test_sanitize_strftime_format_with_escaped_percent
(i18n.tests.FormattingTests.test_sanitize_strftime_format_with_escaped_percent)
(year=1, fmt='%%%%%C')
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/django/tests/i18n/tests.py", line 1227, in
test_sanitize_strftime_format_with_escaped_percent
self.assertEqual(dt.strftime(fmt), expected)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: '%%0' != '%%00'
- %%0
+ %%00
? +


======================================================================
FAIL: test_sanitize_strftime_format_with_escaped_percent
(i18n.tests.FormattingTests.test_sanitize_strftime_format_with_escaped_percent)
(year=1, fmt='%%%%%F')
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/django/tests/i18n/tests.py", line 1227, in
test_sanitize_strftime_format_with_escaped_percent
self.assertEqual(dt.strftime(fmt), expected)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: '%%1-01-01' != '%%0001-01-01'
- %%1-01-01
+ %%0001-01-01
? +++


======================================================================
FAIL: test_sanitize_strftime_format_with_escaped_percent
(i18n.tests.FormattingTests.test_sanitize_strftime_format_with_escaped_percent)
(year=99, fmt='%%%C')
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/django/tests/i18n/tests.py", line 1227, in
test_sanitize_strftime_format_with_escaped_percent
self.assertEqual(dt.strftime(fmt), expected)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: '%0' != '%00'
- %0
+ %00
? +


======================================================================
FAIL: test_sanitize_strftime_format_with_escaped_percent
(i18n.tests.FormattingTests.test_sanitize_strftime_format_with_escaped_percent)
(year=99, fmt='%%%F')
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/django/tests/i18n/tests.py", line 1227, in
test_sanitize_strftime_format_with_escaped_percent
self.assertEqual(dt.strftime(fmt), expected)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: '%99-01-01' != '%0099-01-01'
- %99-01-01
+ %0099-01-01
? ++


======================================================================
FAIL: test_sanitize_strftime_format_with_escaped_percent
(i18n.tests.FormattingTests.test_sanitize_strftime_format_with_escaped_percent)
(year=99, fmt='%%%%%C')
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/django/tests/i18n/tests.py", line 1227, in
test_sanitize_strftime_format_with_escaped_percent
self.assertEqual(dt.strftime(fmt), expected)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: '%%0' != '%%00'
- %%0
+ %%00
? +


======================================================================
FAIL: test_sanitize_strftime_format_with_escaped_percent
(i18n.tests.FormattingTests.test_sanitize_strftime_format_with_escaped_percent)
(year=99, fmt='%%%%%F')
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/django/tests/i18n/tests.py", line 1227, in
test_sanitize_strftime_format_with_escaped_percent
self.assertEqual(dt.strftime(fmt), expected)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: '%%99-01-01' != '%%0099-01-01'
- %%99-01-01
+ %%0099-01-01
? ++


======================================================================
FAIL: test_sanitize_strftime_format_with_escaped_percent
(i18n.tests.FormattingTests.test_sanitize_strftime_format_with_escaped_percent)
(year=999, fmt='%%%C')
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/django/tests/i18n/tests.py", line 1227, in
test_sanitize_strftime_format_with_escaped_percent
self.assertEqual(dt.strftime(fmt), expected)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: '%9' != '%09'
- %9
+ %09
? +


======================================================================
FAIL: test_sanitize_strftime_format_with_escaped_percent
(i18n.tests.FormattingTests.test_sanitize_strftime_format_with_escaped_percent)
(year=999, fmt='%%%F')
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/django/tests/i18n/tests.py", line 1227, in
test_sanitize_strftime_format_with_escaped_percent
self.assertEqual(dt.strftime(fmt), expected)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: '%999-01-01' != '%0999-01-01'
- %999-01-01
+ %0999-01-01
? +


======================================================================
FAIL: test_sanitize_strftime_format_with_escaped_percent
(i18n.tests.FormattingTests.test_sanitize_strftime_format_with_escaped_percent)
(year=999, fmt='%%%%%C')
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/django/tests/i18n/tests.py", line 1227, in
test_sanitize_strftime_format_with_escaped_percent
self.assertEqual(dt.strftime(fmt), expected)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: '%%9' != '%%09'
- %%9
+ %%09
? +


======================================================================
FAIL: test_sanitize_strftime_format_with_escaped_percent
(i18n.tests.FormattingTests.test_sanitize_strftime_format_with_escaped_percent)
(year=999, fmt='%%%%%F')
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/django/tests/i18n/tests.py", line 1227, in
test_sanitize_strftime_format_with_escaped_percent
self.assertEqual(dt.strftime(fmt), expected)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: '%%999-01-01' != '%%0999-01-01'
- %%999-01-01
+ %%0999-01-01
? +
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35630>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 25, 2024, 7:48:29 AM7/25/24
to django-...@googlegroups.com
#35630: `django.utils.formats.sanitize_strftime_format()` no longer works correctly
with Python 3.13.0b4
------------------------------+--------------------------------------
Reporter: Michał Górny | Owner: (none)
Type: Bug | Status: closed
Component: Utilities | Version: dev
Severity: Normal | Resolution: duplicate
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 Sarah Boyce):

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

Comment:

Thank you for drawing this to our attention Michal
I'm going to link this up to #34900 which tracks adding Python 3.13
support 👍
--
Ticket URL: <https://code.djangoproject.com/ticket/35630#comment:1>

Django

unread,
Aug 28, 2024, 9:20:26 AM8/28/24
to django-...@googlegroups.com
#35630: `django.utils.formats.sanitize_strftime_format()` no longer works correctly
with Python 3.13.0b4
------------------------------+--------------------------------------
Reporter: Michał Górny | Owner: (none)
Type: Bug | Status: closed
Component: Utilities | Version: dev
Severity: Normal | Resolution: duplicate
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 Natalia Bidart):

This was nicely reverted and fixed in Python:
https://github.com/python/cpython/pull/122436/
--
Ticket URL: <https://code.djangoproject.com/ticket/35630#comment:2>
Reply all
Reply to author
Forward
0 new messages