Modify

Opened 23 months ago

Last modified 23 months ago

#10424 new defect

Replace propriatary tz handling

Reported by: hasienda Owned by: martin_s
Priority: normal Component: WatchlistPlugin
Severity: normal Keywords: timezone time-stamp
Cc: rjollos Trac Release: 1.0

Description

This traceback was been provided for advice on IRC tonight:

2012-10-03 13:53:12,425 Trac[main] ERROR: Internal Server Error:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/trac/web/main.py", line 511, in _dispatch_request
    dispatcher.dispatch(req)
  File "/usr/lib/python2.7/dist-packages/trac/web/main.py", line 237, in dispatch
    resp = chosen_handler.process_request(req)
  File "/usr/local/lib/python2.7/dist-packages/TracWatchlistPlugin-1.0-py2.7.egg/tracwatchlist/plugin.py", line 589, in process_request
    offset = req.tz.utcoffset(datetime.now(req.tz))
  File "/usr/lib/python2.7/dist-packages/pytz/tzinfo.py", line 401, in utcoffset
    dt = self.localize(dt, is_dst)
  File "/usr/lib/python2.7/dist-packages/pytz/tzinfo.py", line 299, in localize
    raise ValueError('Not naive datetime (tzinfo is already set)')
ValueError: Not naive datetime (tzinfo is already set)

Seems like recent changes to Trac break current code, as hinted by osimons.

Better use functions from trac.util.datefmt for what is needed by the plugin.

Attachments (0)

Change History (2)

comment:1 Changed 23 months ago by hasienda

  • Cc rjollos added

comment:2 Changed 23 months ago by jun66j5

I suggest the following patch to fix the issue and another issue. See trac:ticket:10863#comment:3.

  • tracwatchlist/plugin.py

     
    592592            wldict['show_messages'] = options['show_messages_on_watchlist_page'] 
    593593 
    594594        wldict['perm']   = req.perm 
    595         offset = req.tz.utcoffset(datetime.now(req.tz)) 
     595        offset = datetime.now(req.tz).utcoffset() 
    596596        if offset is None: 
    597597            offset = 0 
    598598        else: 
    599             offset = offset.seconds / 60 
     599            offset = offset.days * 24 * 60 + offset.seconds / 60 
    600600        wldict['tzoffset'] = offset 
    601601        wldict['i18n'] = i18n_enabled 
    602602        wldict['realms'] = [ r for r in settings['listoptions']['realm_order'] if r in self.realms ] 

The another issue is about timezone with negative offset. In the case, utcoffset().days is -1.

$ PYTHONPATH=$PWD ~/venv/py24/bin/python
Python 2.4.3 (#1, Jun 18 2012, 08:55:31)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from trac.util.datefmt import timezone
>>> from datetime import datetime
>>> datetime.now(timezone('America/New_York')).utcoffset()
datetime.timedelta(-1, 72000)
>>> datetime.now(timezone('America/New_York')).utcoffset().days
-1
>>>

Add Comment

Modify Ticket

Action
as new .
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.