2218: Selecting "This month" in server log viewing section results in HTTP 500 status

leel*****@gmai***** (Google Code) (Is this you? Claim this profile.)
chipx86
chipx86
Aug. 13, 2011
What version are you running?
1.6 RC2

What's the URL of the page containing the problem?
http://review.example.com/admin/log/server/?to=2011-08-31&from=2011-08-0

What steps will reproduce the problem?
1. select "Server Log" on the dashboard
2. select "This month" from the Filter/By Date section
3.

What is the expected output? What do you see instead?
Logs for the current month, A 500 error message

What operating system are you using? What browser?
RHEL, Firefox 3

Please provide any additional information below.

It appears, upon initial inspection that the call to calendar.monthrange is returning the tuple (0, 31) for the month of August 2011. calendar.monthrange returns a tuple containing the day of the week (0-6 Mon-Sun) that the month starts on and the number of days in the month. Not the start date (which would be 01 for any month) like the code seems to assume. If we assume that the first day of the month is "1" then we could fix our date formatting by using the "%Y-%m-01" format string instead.

Attached:
logmsg.txt : Error message received
views.py.diff.txt : patch with debugging confirming the output of monthrange
fix.diff.txt : fix
Internal Server Error: /admin/log/server/
Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py", line 111, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "/usr/lib/python2.6/site-packages/django/contrib/admin/views/decorators.py", line 19, in _checklogin
    return view_func(request, *args, **kwargs)
  File "/usr/lib/python2.6/site-packages/Djblets-0.6.9-py2.6.egg/djblets/log/views.py", line 246, in server_log
    from_timestamp = parse_timestamp('%Y-%m-%d', request.GET.get('from'))
  File "/usr/lib/python2.6/site-packages/Djblets-0.6.9-py2.6.egg/djblets/log/views.py", line 72, in parse_timestamp
    return datetime.datetime(*time.strptime(timestamp_str, format)[0:6])
  File "/usr/lib64/python2.6/_strptime.py", line 454, in _strptime_time
    return _strptime(data_string, format)[0]
  File "/usr/lib64/python2.6/_strptime.py", line 325, in _strptime
    (data_string, format))
Va
--- views.py.orig	2011-08-05 16:01:41.000000000 -0600
+++ views.py	2011-08-05 16:01:09.000000000 -0600
@@ -178,7 +178,9 @@
     one_week_ago = today - datetime.timedelta(days=7)
     one_week_ago_str = one_week_ago.strftime('%Y-%m-%d')
     month_range = calendar.monthrange(today.year, today.month)
+    logger.critical(month_range)
     this_month_begin_str = today.strftime('%Y-%m-') + str(month_range[0])
+    logger.critical(this_month_begin_str)
     this_month_end_str = today.strftime('%Y-%m-') + str(month_range[1])
 
     date_filters = [
--- views.py.orig	2011-08-05 16:01:41.000000000 -0600
+++ views.py	2011-08-05 16:01:09.000000000 -0600
@@ -178,7 +178,7 @@
     one_week_ago = today - datetime.timedelta(days=7)
     one_week_ago_str = one_week_ago.strftime('%Y-%m-%d')
     month_range = calendar.monthrange(today.year, today.month)
-    this_month_begin_str = today.strftime('%Y-%m-') + str(month_range[0])
+    this_month_begin_str = today.strftime('%Y-%m-01')
     this_month_end_str = today.strftime('%Y-%m-') + str(month_range[1])
 
     date_filters = [
#1 leel*****@gmai***** (Google Code) (Is this you? Claim this profile.)
http://reviews.reviewboard.org/r/2528/
chipx86
#2 chipx86
Committed to master (6fa6bb8)
  • +Fixed
  • +Djblets
    +Component-Admin
    +Milestone-Release1.6
  • +chipx86