#14711: MonthMixin.get_previous_month incorrect under certain conditions
---------------------------+------------------------------------------------
 Reporter:  msundstr       |       Owner:  nobody    
   Status:  new            |   Milestone:  1.3       
Component:  Generic views  |     Version:  SVN       
 Keywords:                 |       Stage:  Unreviewed
Has_patch:  1              |  
---------------------------+------------------------------------------------
 In the class-based generic views, MonthMixin.get_previous_month will give
 an incorrect result when allow_empty is False and there are no records
 that exist for the first day of the previous month.

 For example, consider the Books model in the generic_views regression test
 cases, with 3 books with the pubdates:
      2010-09-01
      2010-10-02
      2010-11-03

 /dates/books/2010/oct/ should return a context where previous_month is
 2010-09-01
 and
 /dates/books/2010/nov/ should similarly return 2010-10-01

 However, in the second case, 2010-09-01 is returned instead. This is
 because the date that is passed to the helper function,
 _get_next_prev_month, (i.e., naive_result), is 2010-10-01, and the
 subsequent database lookup is for a record before to that date. Hence, the
 existing record dated 2010-10-02, is skipped and the previous month is
 returned instead.

 Changing MonthMixin.get_previous_month to instead pass in the last day of
 the previous month, instead of the first day, fixes this problem.

 Test demonstrating the problem and a patch for
 django.views.generic.dates.py included. (patch fixes 3 typos also)

-- 
Ticket URL: <http://code.djangoproject.com/ticket/14711>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

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

Reply via email to