Opened 12 years ago

Closed 12 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)

17882-quick-n-dirty-patch.diff (1.2 KB ) - added by Aymeric Augustin 12 years ago.
17882-better-fix-with-setting-changed-signal.diff (764 bytes ) - added by Aymeric Augustin 12 years ago.
17882-second-take.patch (4.1 KB ) - added by Aymeric Augustin 12 years ago.

Download all attachments as: .zip

Change History (15)

comment:1 by Jannis Leidel, 12 years ago

Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted

comment:2 by Julien Phalip, 12 years ago

This problem occurs after the changes in [17670].

comment:3 by Aymeric Augustin, 12 years ago

Owner: changed from nobody to Aymeric Augustin

comment:4 by Aymeric Augustin, 12 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 Aymeric Augustin, 12 years ago

comment:5 by Aymeric Augustin, 12 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.

comment:6 by Aymeric Augustin, 12 years ago

Triage Stage: AcceptedDesign 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 Jannis Leidel, 12 years ago

Triage Stage: Design decision neededReady for checkin

I think this ticket is clearly a great use case for the signal, let's use the second patch.

comment:8 by Aymeric Augustin, 12 years ago

Resolution: fixed
Status: newclosed

In [17699]:

Fixed #17882 -- Reopened the database connection when a test changes time zone settings. Thanks brodie for the report.

comment:9 by Aymeric Augustin, 12 years ago

Patch needs improvement: set
Resolution: fixed
Status: closedreopened
Triage Stage: Ready for checkinAccepted

comment:10 by Aymeric Augustin, 12 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 Aymeric Augustin, 12 years ago

Attachment: 17882-second-take.patch added

comment:11 by Aymeric Augustin, 12 years ago

This improved version is unfortunately blocked by #17895.

comment:12 by Aymeric Augustin, 12 years ago

Resolution: fixed
Status: reopenedclosed

In [17709]:

Fixed #17882 (again) -- Updated the database connections' time zone when time-zone-related settings are changed in tests.

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