Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#17580 closed Bug (fixed)

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

Reported by: Jannis Leidel Owned by: Aymeric Augustin
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 by Aymeric Augustin, 13 years ago

Owner: changed from nobody to Aymeric Augustin
Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted

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 by Jannis Leidel, 13 years ago

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 by Aymeric Augustin, 13 years ago

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 by Jannis Leidel, 13 years ago

Resolution: fixed
Status: newclosed

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 by Aymeric Augustin, 13 years ago

In [17403]:

(The changeset message doesn't reference this ticket)

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