#35630 closed Bug (duplicate)
`django.utils.formats.sanitize_strftime_format()` no longer works correctly with Python 3.13.0b4
Reported by: | Michał Górny | Owned by: | |
---|---|---|---|
Component: | Utilities | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Michał Górny | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Python 3.13.0b4 includes a change to 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
This misfires on 3.13.0b4, stopping django from adding the padding to %C
and %F
formats.
I've filed 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 ? +
Change History (2)
comment:1 by , 4 months ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
comment:2 by , 3 months ago
This was nicely reverted and fixed in Python: https://github.com/python/cpython/pull/122436/
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 👍