Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#17580 closed Bug (fixed)

DateTimeFields don't handle timezones when given datetime.date instances

Reported by: jezdez Owned by: aaugustin
Component: Core (Other) Version: 1.4-alpha-1
Severity: Release blocker Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When DateTimeFields get passed datetime.date instances it converts the values in datetime.datetime values, without using the new timezone feature.

source:django/trunk/django/db/models/fields/__init__.py?rev=17148#L750

Change History (5)

comment:1 Changed 4 years ago by aaugustin

  • Owner changed from nobody to aaugustin
  • Severity changed from Normal to Release blocker
  • Triage Stage changed from Unreviewed to Accepted

When time zone support is enabled, the date value should be converted to an aware datetime in the default time zone, with a warning.

comment:2 Changed 4 years ago by jezdez

Agreed in general, but I don't think a warning is appropriate here. Passing a date instance is a perfectly fine use case and can't be made timezone aware like datetime instances by passing a tzinfo parameter.

comment:3 Changed 4 years ago by aaugustin

Indeed, a date can't be timezone aware, which means it can't be interpreted unambiguously as a timezone aware datetime.

That's why I proposed to raise a warning when USE_TZ = True, exactly like I do when a DateTimeField receives a naive datetime.

comment:4 Changed 4 years ago by jezdez

  • Resolution set to fixed
  • Status changed from new to closed

In [17392]:

Fixed #17580 -- Made sure datetime.date instances are correctly handled when being passed to a DateTimeField fields and the timezone support is enabled by making it aware using the default timezone.

comment:5 Changed 4 years ago by aaugustin

In [17403]:

Caught (and tested) the warning added at r17393 in the corresponding test. Refs #17580.

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