Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Problems with date-based generic views when USE_TZ=True
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Mike Yumatov  
View profile  
 More options Apr 27 2012, 8:51 am
From: Mike Yumatov <m...@yumatov.org>
Date: Fri, 27 Apr 2012 16:51:54 +0400
Local: Fri, Apr 27 2012 8:51 am
Subject: Problems with date-based generic views when USE_TZ=True
Hi!

I wrote a ticket about time zone warnings in date-based generic views: https://code.djangoproject.com/ticket/18217

After some research, I understand that there are more problems with this views, than I thought at first. django.views.generic.dates module uses aware and naive datetime objects together, which breaks all date-based views except YearArchiveView.

Let's have, for example:
- America/Chicago as TIME_ZONE
- an article, published at 2012-12-31 23:00:00 in local time zone (2012-01-01 05:00:00 UTC)
- an url /articles/{year}/ which returns list of articles for requested year
- an url /articles/{year}/{month}/ which returns list of articles for requested month

As I understand, year and month must be in UTC in urls, or date_list from all date-based generic views is useless, because it contains dates in UTC.

So, our article must be in /articles/2012/ and in /articles/2012/01/. But it won't be in /articles/2012/01/, because MonthArchiveView will use datetime.date objects, which will be treated as naive datetime.datetime object by ORM, and local time zone will be used.

The same thing is true for DayArchiveView, TodayArchiveView and DateDetailView.

This issue affects trunk and 1.4 versions of Django.

--
Mike Yumatov


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Aymeric Augustin  
View profile  
 More options Apr 27 2012, 1:21 pm
From: Aymeric Augustin <aymeric.augus...@polytechnique.org>
Date: Fri, 27 Apr 2012 19:21:13 +0200
Local: Fri, Apr 27 2012 1:21 pm
Subject: Re: Problems with date-based generic views when USE_TZ=True
Hi Mike,

On 27 avr. 2012, at 14:51, Mike Yumatov wrote:

> I wrote a ticket about time zone warnings in date-based generic views: https://code.djangoproject.com/ticket/18217

It isn't necessary to notify django-developers when you create a ticket; that's the job of django-updates.

> After some research, I understand that there are more problems with this views, than I thought at first. django.views.generic.dates module uses aware and naive datetime objects together, which breaks all date-based views except YearArchiveView.

> Let's have, for example:
> - America/Chicago as TIME_ZONE
> - an article, published at 2012-12-31 23:00:00 in local time zone (2012-01-01 05:00:00 UTC)
> - an url /articles/{year}/ which returns list of articles for requested year
> - an url /articles/{year}/{month}/ which returns list of articles for requested month

> As I understand, year and month must be in UTC in urls

They are in local time in the default time zone.

> or date_list from all date-based generic views is useless, because it contains dates in UTC.

I'm not sure I understand your point there.

> So, our article must be in /articles/2012/ and in /articles/2012/01/. But it won't be in /articles/2012/01/, because MonthArchiveView will use datetime.date objects, which will be treated as naive datetime.datetime object by ORM, and local time zone will be used.

This is an ill-defined problem, and also a hard one.

The behavior you're describing is the expected behavior, it's mostly backwards compatible and in my opinion it's the least unreasonable option.

See also :
https://docs.djangoproject.com/en/dev/topics/i18n/timezones/#faq
http://groups.google.com/group/django-developers/browse_thread/thread...

Best regards,

--
Aymeric.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mike Yumatov  
View profile  
 More options Apr 28 2012, 1:56 am
From: Mike Yumatov <m...@yumatov.org>
Date: Sat, 28 Apr 2012 09:56:28 +0400
Local: Sat, Apr 28 2012 1:56 am
Subject: Re: Problems with date-based generic views when USE_TZ=True
Hi Aymeric,

On Friday, April 27, 2012 at 9:21 PM, Aymeric Augustin wrote:
> > After some research, I understand that there are more problems with this views, than I thought at first. django.views.generic.dates module uses aware and naive datetime objects together, which breaks all date-based views except YearArchiveView.

> > Let's have, for example:
> > - America/Chicago as TIME_ZONE
> > - an article, published at 2012-12-31 23:00:00 in local time zone (2012-01-01 05:00:00 UTC)
> > - an url /articles/{year}/ which returns list of articles for requested year
> > - an url /articles/{year}/{month}/ which returns list of articles for requested month

> > As I understand, year and month must be in UTC in urls

> They are in local time in the default time zone.

Are you sure? Because if so, YearArchiveView is broken: it uses year lookup (https://docs.djangoproject.com/en/1.4/ref/models/querysets/#year), which is performed in UTC.

Also, date_list context variable from all this views becomes useless, because in contains datetime.datetime objects in UTC. You can't use date_list to build urls in templates in this case. E.g. we have two articles: the first is published at 2012-04-27 in local time zone and at 2012-04-28 in UTC, and the second is published at 2012-04-28 in local time zone and at 2012-04-28 in UTC. date_list from MonthArchiveView will contain only one date - 2012-04-28 in UTC. Depending on what time zone we will use in template to build urls to DayArchiveView (local time zone or UTC), first or second article will not be present in output of this view.

And also, URLs to date-based views become dependent on current time zone (which can be changed for request on some projects), so you can't share this URLs with others and be sure, that they will work for others.

--
Mike Yumatov


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Aymeric Augustin  
View profile  
 More options Apr 28 2012, 2:40 am
From: Aymeric Augustin <aymeric.augus...@polytechnique.org>
Date: Sat, 28 Apr 2012 08:40:26 +0200
Local: Sat, Apr 28 2012 2:40 am
Subject: Re: Problems with date-based generic views when USE_TZ=True
On 28 avr. 2012, at 07:56, Mike Yumatov wrote:

>> They are in local time in the default time zone.
> Are you sure? Because if so, YearArchiveView is broken: it uses year lookup (https://docs.djangoproject.com/en/1.4/ref/models/querysets/#year), which is performed in UTC.

Indeed, you're right, sorry.

In fact a very similar problem was already fixed in the admin following #17830 [1].

I've reopened #18217 [2] for filtering ranges properly. In the current state the list of years, months, days in date_list may still be slightly off. That's in the realm of #17260 [3].

Best regards,

--
Aymeric.

[1] https://code.djangoproject.com/ticket/17830
[2] https://code.djangoproject.com/ticket/18217
[3] https://code.djangoproject.com/ticket/17260


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »