update_index should use non-naive datetime when settings.USE_TZ=True #682

merged 2 commits into from Dec 11, 2012


None yet
2 participants

acdha commented Nov 16, 2012

After upgrading to Django 1.4 and setting USE_TZ = True, the update_index management command will cause the following warning:

RuntimeWarning: DateTimeField received a naive datetime (2012-11-06 09:33:16.701622) while time zone support is active.

Besides being annoying, this actually breaks if you use an interval less than your GMT offset: for example, on the East Coast update_index -a5 will exclude everything while -a 6 will work.

From first glance, this might be something like a conditional import to use Django 1.4's USE_TZ-aware compatibility layer:

    from django.utils.timezone import now
except ImportError:
    from datetime import datetime
    now = datetime.now

acdha added some commits Nov 16, 2012

update_index: use tz-aware datetime where applicable
This will allow Django 1.4 users with USE_TZ=True to use update_index with time
windowing as expected - otherwise the timezone offset needs to be manually
included in the value passed to -a
Tests for update_index timezone support
* Confirm that update_index --age uses the Django timezone-aware now
  support function
* Skip this test on Django 1.3

toastdriven commented Dec 11, 2012

Yes please. This has bothered me for a long time. :shipit:

acdha added a commit that referenced this pull request Dec 11, 2012

Merge pull request #682 from acdha/682-update_index-tz-support
update_index should use non-naive datetime when settings.USE_TZ=True

@acdha acdha merged commit 3ceaa8d into django-haystack:master Dec 11, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment