﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
35630	`django.utils.formats.sanitize_strftime_format()` no longer works correctly with Python 3.13.0b4	Michał Górny		"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
?   +
}}}"	Bug	closed	Utilities	dev	Normal	duplicate		Michał Górny	Unreviewed	0	0	0	0	0	0
