Opened 9 months ago

Closed 9 months ago

Last modified 9 months ago

#35293 closed Bug (needsinfo)

Django 5.x changes the date format on an <input type="date"> from "2012-10-01" to "01/10/2012"

Reported by: Shaheed Haque Owned by: nobody
Component: Template system Version: 5.0
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

We are attempting to migrate from Django 4.11 to Django 5.0.latest. Our tests identified that Date inputs which were previous rendered with a "value" attribute in ISO8601 date format now seem to be rendered using en-GB. Here is what the 4.x renders:

<input type="date" name="..." value="2012-10-01" class=" form-control" required="" id="...">

versus what 5.x renders:

<input type="date" name="..." value="01/10/2012" class=" form-control" required="" aria-describedby="..." id="...">

Our settings have not changed. Here is a subset of what we have:

LANGUAGE_CODE = 'en-gb'
LANGUAGES = (
    ('en-gb', _('English (GB)')),
)
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = False
USE_TZ = True

Note that we do NOT have any of the DATE_FORMAT, DATE_INPUT_FORMATS etc. set, so they should have their default values. I have reviewed the release notes but did not see anything relevant. I have tried debugging the code in django.utils.formats but is not clear to me where the difference originates.

In case it is relevant, we are using the Jinja backend with bootstrap styling and our own templates, but the core "field" rendering should be whatever Django does.

Change History (4)

comment:1 by Tim Graham, 9 months ago

Resolution: needsinfo
Status: newclosed
Type: UncategorizedBug

The description mentions Django 4.11 but this isn't a valid version. Did you mean 4.1?

This looks relevant from the Djagno 5.0 release notes, "The USE_L10N setting is removed." (8d98f99a4ab5de6f2c730399f53eba8bf6bea470) Did you test your project with deprecation warnings enabled? Does the behavior change in Django 4.x if setting USE_L10N=True.

If that's not the cause, you can try bisecting to find the commit where the behavior changed.

If you need help debugging, see TicketClosingReasons/UseSupportChannels and reopen the ticket if you determine this is a bug in Django.

comment:2 by David Sanders, 9 months ago

To further Tim's points, if you look back at the 4.0 release notes it documents that USE_L10N = True is the _default_ behaviour which means that in Django 5.0 you now need to override where Django finds its localisation if you want to preserve the "old default" values for DATE_FORMAT, etc.

Please see: https://docs.djangoproject.com/en/5.0/topics/i18n/formatting/#creating-custom-format-files

comment:3 by Shaheed Haque, 9 months ago

FWIW, I meant to say I was running version 4.2.11, but I had not spotted the need to create custom format files. Thanks for the pointer.

comment:4 by Claude Paroz, 9 months ago

Note that Django itself has no widgets having input type="date" by default. This issue may be related to some custom code. See for example an implementation in one of my projects:

class DateInput(forms.DateInput):
    input_type = 'date'

    def format_value(self, value):
        return str(value) if value is not None else None

See also #33113

Note: See TracTickets for help on using tickets.
Back to Top