Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#17940 closed Bug (fixed)

RuntimeWarning when running the test suite on a new project

Reported by: Aymeric Augustin Owned by: Aymeric Augustin
Component: contrib.auth Version: dev
Severity: Release blocker Keywords:
Cc: slacy@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

(reported on IRC)

19-21:33:09      carljm mYk: is there already an open ticket about the fact that when you start a new project and run its tests, you get RuntimeWarnings about timezones?
19-22:17:43      carljm mYk: it's in the contrib.auth tests
19-22:17:48      carljm three occurrences
19-22:17:57      carljm haven't tracked it down to the specific tests yet
19-22:18:10      carljm reproduction is just "startproject, configure db, manage.py test auth"
19-22:22:07       cramm carljm, mYk: /manage.py test -v2 auth.AuthContextProcessorTests.test_message_attrs auth.AuthViewNamedURLTests.test_named_urls auth.LoadDataWithNaturalKeysTestCase.test_user_is_created_and_added_to_group
19-22:22:28       cramm these are the three tests to run to reproduce what Carl reports

(reported in the comments of #17275)

I'm just switching our codebase to 1.4c2 and have run into this issue in the test suites.

To make sure it wasn't something I was doing, I did the following:

$ django-admin.py startproject blank 
$ cd blank/blank
$ <edit settings.py and set DB ENGINE to 'django.db.backends.sqlite3'
$ django-admin.py test 

Creating test database for alias 'default'...
..../home/slacy/src/oswebsite/wsve/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py:808: RuntimeWarning: DateTimeField received a naive datetime (2007-05-30 13:20:10) while time zone support is active.
  RuntimeWarning)
...../home/slacy/src/oswebsite/wsve/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py:808: RuntimeWarning: DateTimeField received a naive datetime (2006-12-17 07:03:31) while time zone support is active.
  RuntimeWarning)
........................../home/slacy/src/oswebsite/wsve/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py:808: RuntimeWarning: DateTimeField received a naive datetime (2012-01-13 00:14:00) while time zone support is active.
  RuntimeWarning)
...............................................................................................................................................................................................................................................................................................................s.......................................................................
----------------------------------------------------------------------
Ran 410 tests in 10.039s

OK (skipped=1)
Destroying test database for alias 'default'...

Attachments (1)

17940.patch (6.2 KB ) - added by Aymeric Augustin 13 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 by Aymeric Augustin, 13 years ago

FYI the easiest way to debug this is to turn warning into exceptions as explained in the docs.

comment:2 by Aymeric Augustin, 13 years ago

Has patch: set

The root cause of the problem lies in the fixtures used by the tests of django.contrib.auth. As explained in the docs (once again!) it isn't possible to write fixtures that work both with and without USE_TZ.

The easiest solution is to override_settings(USE_TZ=False) in all tests that use fixtures.


This problem only affects contrib apps, whose tests are likely to be run with non-default settings.

A quick find shows that auth, flatpages and gis use fixtures and may suffer from the problem:

% find django -name .svn -prune -o -path \*/fixtures/\* -type f -print
django/contrib/auth/fixtures/authtestdata.json
django/contrib/auth/fixtures/context-processors-users.xml
django/contrib/auth/fixtures/natural.json
django/contrib/auth/fixtures/regular.json
django/contrib/flatpages/fixtures/sample_flatpages.json
django/contrib/gis/tests/distapp/fixtures/initial_data.json.gz
django/contrib/gis/tests/geoapp/fixtures/initial_data.json.gz
django/contrib/gis/tests/geogapp/fixtures/initial_data.json
django/contrib/gis/tests/relatedapp/fixtures/initial_data.json.gz

Upon closer inspection, only the auth fixtures contain serialized datetime objects, so the fix only needs to be applied to auth.

by Aymeric Augustin, 13 years ago

Attachment: 17940.patch added

comment:3 by Aymeric Augustin, 13 years ago

Resolution: fixed
Status: newclosed

In [17770]:

Fixed #17940 -- Enforced USE_TZ = False in contrib apps tests that use fixtures containing datetimes.

comment:4 by Steve Lacy, 13 years ago

Cc: slacy@… added

comment:5 by Steve Lacy, 13 years ago

This bug fix has introduced another bug #17966 which is in 1.4 final. Sigh. :)

Last edited 13 years ago by Steve Lacy (previous) (diff)
Note: See TracTickets for help on using tickets.
Back to Top