Monday, January 30, 2012

Re: Question regarding ticket #17062

On Jan 30, 11:21 am, Ashe <matthieu....@gmail.com> wrote:
> Hello,
>
> I have been using django 1.3.1 for some months.
> I had a long time bug and I finally took some hours to track it.
> Sometimes in my admin interface (not the default django one), all the
> query based on datetime object have a very strange behavior.
> After some research, I ended up with the conclusion that
> transaction.rollback puts my postgresql database in the server
> timezone, despite TIME_ZONE being set at UTC.
>
> With that information, I found this ticket (https://code.djangoproject.com/ticket/17062
> ) and this changeset (https://code.djangoproject.com/changeset/17128
> ). So apparently it's solved in the trunk.
>
> I'm using some transactions for some really important administration
> tasks that modify multiple tables at the same time. I can't change
> that, and I really need to solve my query issue.
> I'm not authorized to change the timezone of the server (on
> webfaction).
> Could you help me make this modification working in the 1.3.1 ? I
> looked at the file modified in the changeset 17128, but it looks like
> it changed a lot between the release and this changeset.
> Or would you recommend to install the trunk ? I won't hide that I'm a
> bit scarred to put a trunk version on production.
> Will it be in the 1.4 ? I wasn't able to tell from the changeset page.

If you don't want to use a custom version of Django, and can't wait
for 1.4, you should be able to set the time zone for per database
user. Connect to the database with your database user, and do this:
ALTER USER "thedbuser" SET TIME ZONE 'wanted_zone'; -- where
wanted_zone would be UTC for you.
So, for example for me the above would look:
ALTER USER "akaariai" SET TIME ZONE 'Europe/Helsinki';

The per-user settings are a really nice feature. Many problems in
PostgreSQL can be neatly solved by usage of the per-user settings.

You can verity that the change took place by reconnecting (the per
user settings are only changed on connect), and running:
select current_setting('timezone');

The effect of this is that the rollback will still reset you timezone,
but as the default is UTC there is nothing to worry :) In fact, once
1.4 is out, it will no longer run SET TIME ZONE at all, as 1.4 is able
to recognize that the time zone is already correct for the connection!

- Anssi

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment