USE_TZ related warnings caused by fixture loading

457 views
Skip to first unread message

Yo-Yo Ma

unread,
Mar 1, 2012, 10:40:04 AM3/1/12
to django-d...@googlegroups.com
django/db/models/fields/__init__.py:808: RuntimeWarning: DateTimeField received a naive datetime (2012-01-01 00:00:00) while time zone support is active.

The above warning is caused by a JSON fixture having "2012-01-01 00:00:00" for a DateTimeField timestamp.

Does this mean that fixture loading needs to be modified to account for the new timezone code, or was is this just a side effect of keeping fixture loading backward-compatible?

Aymeric Augustin

unread,
Mar 1, 2012, 10:58:51 AM3/1/12
to django-d...@googlegroups.com
2012/3/1 Yo-Yo Ma <baxters...@gmail.com>

django/db/models/fields/__init__.py:808: RuntimeWarning: DateTimeField received a naive datetime (2012-01-01 00:00:00) while time zone support is active.

The above warning is caused by a JSON fixture having "2012-01-01 00:00:00" for a DateTimeField timestamp.

Indeed, a fixture that was generated with USE_TZ = False (or before time zone support existed) will raise warnings when it's loaded with USE_TZ = True.

Does this mean that fixture loading needs to be modified to account for the new timezone code, or was is this just a side effect of keeping fixture loading backward-compatible?

The code is backwards compatible: assuming you haven't changed TIME_ZONE, you will get the data you expect in the database. The warning is just a hint that you should regenerate your fixture.
 
One of the goal of time zone support was to ensure that developers don't accidentally perform "unsafe" (under-specified) operations. Interpreting the naive datetime stored in your fixture in an aware environment is unsafe. Whenever this sort of thing happens, Django raises a warning.

 -- 
Aymeric.

Jacob Kaplan-Moss

unread,
Mar 1, 2012, 11:47:14 AM3/1/12
to django-d...@googlegroups.com
Aymeric Augustin wrote:
> Indeed, a fixture that was generated with USE_TZ = False (or before time
> zone support existed) will raise warnings when it's loaded with USE_TZ =
> True.

Ahha - I've been seeing that warning and haven't been able to interpret
it yet.

Can we possible change the warning to be more clear about what's causing
it? Or at the very least add a note to the release docs about upgrading
fixtures? It's an annoying warning, and the message (to me) doesn't
point very clearly at the cause.

Jacob

Aymeric Augustin

unread,
Mar 1, 2012, 12:12:20 PM3/1/12
to django-d...@googlegroups.com
2012/3/1 Jacob Kaplan-Moss <ja...@jacobian.org>
Sure, I'll take care of this.

--
Aymeric.

Aymeric Augustin

unread,
Mar 3, 2012, 9:04:37 AM3/3/12
to django-d...@googlegroups.com
On 1 mars 2012, at 18:12, Aymeric Augustin wrote:
Sure, I'll take care of this.


Feel free to comment on #17738 or open a new ticket if you have more questions.

Best regards,

-- 
Aymeric.

Reply all
Reply to author
Forward
0 new messages