Opened 5 months ago

Closed 5 months ago

#35097 closed Cleanup/optimization (fixed)

Test utils.dateparse.parse_datetime() with a bare date

Reported by: David Wobrock Owned by: nobody
Component: Utilities Version: 4.0
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hey,

A bit late to the party, but in 4.0, we introduced a patch that changed the behaviour of django.utils.dateparse.parse_datetime.
In very short, on Django 3.2

>>> from django.utils.dateparse import parse_datetime
>>> parse_datetime('2023-01-01')
# Returns None

And on Django 4.0,

>>> from django.utils.dateparse import parse_datetime
>>> parse_datetime('2023-01-01')
datetime.datetime(2023, 1, 1, 0, 0)

The change was introduced in f35ab74752adb37138112657c1bc8b91f50e799b, which relates to #32892.
The initial ticket considers mainly parse_time and parse_date, but not the impacts on parse_datetime.

I think this behaviour is valid, since a date without time can be considered a valid datetime object, with 0 as time values.
But since this change was not documented, I wanted to report it somewhere, because I couldn't find any other reference to it :)

Though I'm not sure this is the best way to share this information, so feel free to close the ticket.

Change History (4)

comment:1 by Mariusz Felisiak, 5 months ago

Resolution: invalid
Status: newclosed

Thanks for the report, however, I'd treat pre-Django 4.0 behavior as a bug here and we don't document bugfixes.

comment:2 by David Wobrock, 5 months ago

Makes sense! Thanks for your time Mariusz.

comment:3 by Tim Graham, 5 months ago

Has patch: set
Resolution: invalid
Status: closednew
Summary: Undocumented behaviour change of utils.dateparse.parse_datetimeTest utils.dateparse.parse_datetime() with a bare date
Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization

PR to add a regression test.

comment:4 by GitHub <noreply@…>, 5 months ago

Resolution: fixed
Status: newclosed

In ecd3071:

Fixed #35097 -- Tested parse_datetime() with bare date.

Regression test for behavior change in
f35ab74752adb37138112657c1bc8b91f50e799b.

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