Edgewall Software
Modify

Opened 8 years ago

Closed 8 years ago

#12489 closed defect (fixed)

ValueError: year=1899 is before 1900; the datetime strftime() methods require year >= 1900

Reported by: Ryan J Ollos Owned by: Ryan J Ollos
Priority: normal Milestone: 1.0.12
Component: general Version: 1.0.11
Severity: normal Keywords: datetime
Cc: Branch:
Release Notes:

Fix ValueError in timeline when prev/next navigation items directed to a year prior to 1900.

API Changes:
Internal Changes:

Description

Maybe we can raise a TracError for this case, or add/or a warning to the timeline page.

2016-05-26 14:42:07,161 Trac[main] ERROR: Internal Server Error: <RequestWithSession "GET '/timeline?from=1900-01-02&daysback=7&authors='">, referrer 'https://bugs.jqueryui.com/'
Traceback (most recent call last):
  File "/var/www/bugs.jqueryui.com/private/pve/local/lib/python2.7/site-packages/trac/web/main.py", line 562, in _dispatch_request
    dispatcher.dispatch(req)
  File "/var/www/bugs.jqueryui.com/private/pve/local/lib/python2.7/site-packages/trac/web/main.py", line 249, in dispatch
    resp = chosen_handler.process_request(req)
  File "/var/www/bugs.jqueryui.com/private/pve/local/lib/python2.7/site-packages/trac/timeline/web_ui.py", line 251, in process_request
    format='%Y-%m-%d', tzinfo=req.tz)
  File "/var/www/bugs.jqueryui.com/private/pve/local/lib/python2.7/site-packages/trac/util/datefmt.py", line 318, in format_date
    return _format_datetime(t, format, tzinfo, locale, 'date')
  File "/var/www/bugs.jqueryui.com/private/pve/local/lib/python2.7/site-packages/trac/util/datefmt.py", line 299, in _format_datetime
    return _format_datetime_without_babel(t, format)
  File "/var/www/bugs.jqueryui.com/private/pve/local/lib/python2.7/site-packages/trac/util/datefmt.py", line 246, in _format_datetime_without_babel
    text = t.strftime(str(format))
ValueError: year=1899 is before 1900; the datetime strftime() methods require year >= 1900

Attachments (0)

Change History (7)

comment:1 by Ryan J Ollos, 8 years ago

Milestone: 1.0.12
Owner: set to Ryan J Ollos
Status: newassigned

Proposed changes in log:rjollos.git:t12489_year_1899.

comment:2 by Jun Omae, 8 years ago

I don't agree [3e45f669/rjollos.git] because the change would lead unexpected result if across DST boundary.

comment:3 by Jun Omae, 8 years ago

We could simply use 'iso8601' format to solve the original issue.

  • trac/timeline/web_ui.py

    diff --git a/trac/timeline/web_ui.py b/trac/timeline/web_ui.py
    index 15f8c79af..862c36650 100644
    a b class TimelineModule(Component):  
    248248        previous_start = fromdate.replace(tzinfo=None) - \
    249249                         timedelta(days=daysback + 1)
    250250        previous_start = format_date(to_datetime(previous_start, req.tz),
    251                                      format='%Y-%m-%d', tzinfo=req.tz)
     251                                     format='iso8601', tzinfo=req.tz)
    252252        add_link(req, 'prev', req.href.timeline(from_=previous_start,
    253253                                                authors=authors,
    254254                                                daysback=daysback),
    class TimelineModule(Component):  
    257257            next_start = fromdate.replace(tzinfo=None) + \
    258258                         timedelta(days=daysback + 1)
    259259            next_start = format_date(to_datetime(next_start, req.tz),
    260                                      format='%Y-%m-%d', tzinfo=req.tz)
     260                                     format='iso8601', tzinfo=req.tz)
    261261            add_link(req, 'next', req.href.timeline(from_=next_start,
    262262                                                    authors=authors,
    263263                                                    daysback=daysback),

in reply to:  2 ; comment:4 by Ryan J Ollos, 8 years ago

Replying to Jun Omae:

I don't agree [3e45f669/rjollos.git] because the change would lead unexpected result if across DST boundary.

I noticed that the naive datetime object is immediately converted to a tz-aware datetime object in _format_datetime, which is called by format_date. Therefore to_datetime(next_start, req.tz) in trac.timeline.web_ui appears to be redundant.

comment:5 by Ryan J Ollos, 8 years ago

Release Notes: modified (diff)

Yeah, comment:3 is the simpler solution. Committed to 1.0-stable in [14810], merged to trunk in [14811]. Added test in [14816,14819], merged to trunk in [14817:14818,14820].

Last edited 8 years ago by Ryan J Ollos (previous) (diff)

in reply to:  4 comment:6 by Jun Omae, 8 years ago

Replying to Ryan J Ollos:

Replying to Jun Omae:

I don't agree [3e45f669/rjollos.git] because the change would lead unexpected result if across DST boundary.

I noticed that the naive datetime object is immediately converted to a tz-aware datetime object in _format_datetime, which is called by format_date. Therefore to_datetime(next_start, req.tz) in trac.timeline.web_ui appears to be redundant.

Ok. You're right. I've misunderstood. Please apply it.

comment:7 by Ryan J Ollos, 8 years ago

Resolution: fixed
Status: assignedclosed

Thanks. The minor change was committed in [14821], merged in [14822].

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Ryan J Ollos.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Ryan J Ollos to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.