Edgewall Software
Modify

Opened 8 years ago

Last modified 15 months ago

#12825 new defect

OverflowError is raised from to_datetime()

Reported by: Jun Omae Owned by:
Priority: normal Milestone: next-stable-1.6.x
Component: timeline Version:
Severity: normal Keywords:
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description (last modified by Jun Omae)

to_datetime() has an issue while invoking pytz.tzinfo.normalize(): /timeline?from=0001-01-01T01:00:00Z&daysback=0

Traceback (most recent call last):
  File "build/bdist.linux-x86_64/egg/trac/web/main.py", line 567, in _dispatch_request
    dispatcher.dispatch(req)
  File "build/bdist.linux-x86_64/egg/trac/web/main.py", line 249, in dispatch
    resp = chosen_handler.process_request(req)
  File "build/bdist.linux-x86_64/egg/trac/timeline/web_ui.py", line 181, in process_request
    timedelta(days=daysback + 1), req.tz)
  File "build/bdist.linux-x86_64/egg/trac/util/datefmt.py", line 177, in to_datetime
    return tz.normalize(dt)
  File "build/bdist.linux-x86_64/egg/trac/util/datefmt.py", line 1049, in normalize
    return self.fromutc(dt.replace(tzinfo=self) - dt.utcoffset())
OverflowError: date value out of range

ValueError also can be raised.

>>> from trac.util.datefmt import to_datetime
>>> to_datetime(-10000000000000000000)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/venv/trac/1.0.13/lib/python2.5/site-packages/trac/util/datefmt.py", line 170, in to_datetime
    dt = datetime.fromtimestamp(integer - 1, tz) + \
ValueError: year is out of range
>>> to_datetime(+10000000000000000000)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/venv/trac/1.0.13/lib/python2.5/site-packages/trac/util/datefmt.py", line 173, in to_datetime
    dt = datetime.fromtimestamp(t, tz)
ValueError: year is out of range

I think we should catch ValueError and OverflowError, and raise a TracError (TracValueError if 1.2.1+) rather than.

Another case, timeline module has the same issue: /timeline?from=0001-01-01T01:00:00Z&daysback=3

Traceback (most recent call last):
  File "build/bdist.linux-x86_64/egg/trac/web/main.py", line 567, in _dispatch_request
    dispatcher.dispatch(req)
  File "build/bdist.linux-x86_64/egg/trac/web/main.py", line 249, in dispatch
    resp = chosen_handler.process_request(req)
  File "build/bdist.linux-x86_64/egg/trac/timeline/web_ui.py", line 181, in process_request
    timedelta(days=daysback + 1), req.tz)
OverflowError: date value out of range

Attachments (0)

Change History (7)

comment:1 by Jun Omae, 8 years ago

Description: modified (diff)

comment:2 by Ryan J Ollos, 7 years ago

Milestone: next-stable-1.0.x1.0.17

Assigning to 1.0.17, since I hope that to be the last 1.0.x release unless major defects or security issues arise.

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

comment:3 by Ryan J Ollos, 6 years ago

Milestone: 1.0.171.0.18

comment:4 by Ryan J Ollos, 6 years ago

Milestone: 1.0.18next-stable-1.0.x

comment:5 by Ryan J Ollos, 5 years ago

Milestone: next-stable-1.0.x1.0.20

comment:6 by Ryan J Ollos, 5 years ago

Milestone: 1.0.20next-stable-1.4.x

Please move back to 1.0.20 if you wish to fix for release 1.0.20 (#13294).

comment:7 by Ryan J Ollos, 15 months ago

Milestone: next-stable-1.4.xnext-stable-1.6.x

Milestone renamed

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The ticket will remain with no owner.
The ticket will be disowned.
as The resolution will be set. Next status will be 'closed'.
The owner will be changed from (none) to anonymous. Next status will be 'assigned'.

Add Comment


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