Opened 13 years ago
Closed 13 years ago
#17882 closed Bug (fixed)
regressiontests.admin_filters fails with pyscopg2 when USE_TZ is False
Reported by: | Brodie Rao | Owned by: | Aymeric Augustin |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Release blocker | Keywords: | |
Cc: | Aymeric Augustin, Jannis Leidel | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
With these settings:
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'djangotest', 'USER': 'djangotest', 'PASSWORD': 'djangotest', }, 'other': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'djangotestother', 'USER': 'djangotestother', 'PASSWORD': 'djangotestother', } } SECRET_KEY = "django_tests_secret_key"
Running the admin_filters test from trunk (at [17682]) fails when testing time zone support:
Creating test database for alias 'default'... Creating test database for alias 'other'... ....E........... ====================================================================== ERROR: test_datefieldlistfilter_with_time_zone_support (regressiontests.admin_filters.tests.ListFiltersTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "django/django/test/utils.py", line 214, in inner return test_func(*args, **kwargs) File "django/tests/regressiontests/admin_filters/tests.py", line 227, in test_datefieldlistfilter_with_time_zone_support self.test_datefieldlistfilter() File "django/tests/regressiontests/admin_filters/tests.py", line 146, in test_datefieldlistfilter changelist = self.get_changelist(request, Book, modeladmin) File "django/tests/regressiontests/admin_filters/tests.py", line 140, in get_changelist modeladmin.list_select_related, modeladmin.list_per_page, modeladmin.list_max_show_all, modeladmin.list_editable, modeladmin) File "django/django/contrib/admin/views/main.py", line 70, in __init__ self.query_set = self.get_query_set(request) File "django/django/contrib/admin/views/main.py", line 322, in get_query_set raise IncorrectLookupParameters(e) IncorrectLookupParameters: database connection isn't set to UTC ---------------------------------------------------------------------- Ran 16 tests in 0.628s FAILED (errors=1) Destroying test database for alias 'default'... Destroying test database for alias 'other'...
Adding USE_TZ = True
to the settings file makes the test pass. I suspect the test is failing because, despite it using @override_settings(USE_TZ=True)
, the current database connection isn't set up to use time zones.
Attachments (3)
Change History (15)
comment:1 by , 13 years ago
Severity: | Normal → Release blocker |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 13 years ago
comment:3 by , 13 years ago
Owner: | changed from | to
---|
comment:4 by , 13 years ago
Surprisingly, this failure doesn't show up on the CI server.
However, I can reproduce it locally. It's probably just a matter of closing the connection so it gets reestablished with the proper "SET TIME ZONE" command.
by , 13 years ago
Attachment: | 17882-quick-n-dirty-patch.diff added |
---|
comment:5 by , 13 years ago
Has patch: | set |
---|
That's a quick fix. I'm now looking at what it would take to use the settings_changed signal.
by , 13 years ago
Attachment: | 17882-better-fix-with-setting-changed-signal.diff added |
---|
comment:6 by , 13 years ago
Triage Stage: | Accepted → Design decision needed |
---|
I have a preference for the second patch, but I'm not sure how we want to use setting_changed
in 1.4 exactly -- see #17787. DDN until this is clarified.
comment:7 by , 13 years ago
Triage Stage: | Design decision needed → Ready for checkin |
---|
I think this ticket is clearly a great use case for the signal, let's use the second patch.
comment:9 by , 13 years ago
Patch needs improvement: | set |
---|---|
Resolution: | fixed |
Status: | closed → reopened |
Triage Stage: | Ready for checkin → Accepted |
The fix appears incorrect: http://ci.djangoproject.com/job/Django/882/
comment:10 by , 13 years ago
I can reproduce the failure locally under MySQL but not under PostgreSQL. I don't understand why yet...
(django-dev)myk@mYk tests % PYTHONPATH=.. python2.7 runtests.py --settings=test_mysql admin_filters cache timezones Creating test database for alias 'default'... Creating test database for alias 'other'... ....F......................................................sssssss..s..............s.....s....................................................................................................................................................................................................................ssssssssssssssssssssssssssssssssss ====================================================================== FAIL: test_datefieldlistfilter_with_time_zone_support (regressiontests.admin_filters.tests.ListFiltersTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "/Users/myk/Documents/dev/django-trunk/django/test/utils.py", line 214, in inner return test_func(*args, **kwargs) File "/Users/myk/Documents/dev/django-trunk/tests/regressiontests/admin_filters/tests.py", line 227, in test_datefieldlistfilter_with_time_zone_support self.test_datefieldlistfilter() File "/Users/myk/Documents/dev/django-trunk/tests/regressiontests/admin_filters/tests.py", line 154, in test_datefieldlistfilter self.assertEqual(list(queryset), [self.django_book, self.djangonaut_book]) AssertionError: Lists differ: [] != [<Book: The Django Book>, <Boo... Second list contains 2 additional elements. First extra element 0: The Django Book - [] + [<Book: The Django Book>, <Book: Djangonaut: an art of living>] ---------------------------------------------------------------------- Ran 336 tests in 56.977s FAILED (failures=1, skipped=44) Destroying test database for alias 'default'... Destroying test database for alias 'other'... PYTHONPATH=.. python2.7 runtests.py --settings=test_mysql admin_filters cache 12,88s user 1,65s system 22% cpu 1:03,86 total (django-dev)myk@mYk tests % PYTHONPATH=.. python2.7 runtests.py --settings=test_postgresql admin_filters cache timezones Creating test database for alias 'default'... Got an error creating the test database: database "test_django" already exists Type 'yes' if you would like to try deleting the test database 'test_django', or 'no' to cancel: yes Destroying old test database 'default'... .............................................................s.s.ss..s..............s.....s...................................................................................................................................................................................................................ssssssssssssssssssssssssssssssssss ---------------------------------------------------------------------- Ran 336 tests in 72.750s OK (skipped=41) Destroying test database for alias 'default'... PYTHONPATH=.. python2.7 runtests.py --settings=test_postgresql admin_filters 22,06s user 1,99s system 30% cpu 1:19,27 total
by , 13 years ago
Attachment: | 17882-second-take.patch added |
---|
This problem occurs after the changes in [17670].