#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.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070190e97f5a03-6349abb8-2333-40b6-a864-65ac3b675b2b-000000%40eu-central-1.amazonses.com.

Reply via email to