3

I am using the fixtures generated from dumpdata for unittests. But I am getting warnings about naive datetime used:

RuntimeWarning: DateTimeField Entry.expire received a naive datetime

A quick look at fixture shows the datetime is generated in this format:

"2014-06-06T00:00:00Z"

which is not timezone aware, reading about the manual makes me guess that dumpdata should generate the timezone aware datetime strings, obviously not in my case.

James Lin
  • 25,028
  • 36
  • 133
  • 233
  • It is timezone aware, because of the suffix [`Z`](http://stackoverflow.com/questions/9706688/what-does-the-z-mean-in-unix-timestamp-120314170138z). Does [this](http://stackoverflow.com/questions/18622007/runtimewarning-datetimefield-received-a-naive-datetime) help? – okm Mar 11 '14 at 01:31
  • @okm okay, how do I make dumpdata to export `+00:00` format instead of `Z` or make unittest to understand the `Z` format? – James Lin Mar 11 '14 at 01:40
  • Does [this link](http://stackoverflow.com/questions/18622007/runtimewarning-datetimefield-received-a-naive-datetime) and [this](https://docs.djangoproject.com/en/dev/topics/i18n/timezones/#code) help? You could either disable `USE_TZ` for test mode or check whether its caused by a naive datetime from otherwhere of fixture or code. I haven't met this issue in 1.6, will check it later. – okm Mar 11 '14 at 02:19
  • I would prefer not to disable `USE_TZ` in unittest as it should reflect the real environment, I am struggling to find out where it would cause to dumpdata in this format as there is no customisation to the models. – James Lin Mar 11 '14 at 06:17
  • I tried and it worked: `2014-06-06T00:00:00Z` was loaded as `datetime.datetime(2014, 6, 6, 0, 0, tzinfo=)` without problem. Being stripped out of 'Z', it was loaded as `datetime.datetime(2014, 6, 5, 16, 0, tzinfo=)` (I'm in UTC+8:00 zone) and with a `RuntimeWarning: DateTimeField ... received a naive datetime (2014-06-06 00:00:00) while time zone support is active.`. Could you simplify your fixture by for example leaving only one item and try it again? – okm Mar 12 '14 at 02:02

0 Answers0