Ticket #10424 (new defect)

Opened 8 months ago

Last modified 8 months ago

Replace propriatary tz handling

Reported by: hasienda Assigned to: 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

Change History

10/04/12 00:07:02 changed by hasienda

  • cc set to rjollos.

10/04/12 04:11:08 changed by jun66j5

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

Index: tracwatchlist/plugin.py
===================================================================
--- tracwatchlist/plugin.py     (revision 12107)
+++ tracwatchlist/plugin.py     (working copy)
@@ -592,11 +592,11 @@
             wldict['show_messages'] = options['show_messages_on_watchlist_page']

         wldict['perm']   = req.perm
-        offset = req.tz.utcoffset(datetime.now(req.tz))
+        offset = datetime.now(req.tz).utcoffset()
         if offset is None:
             offset = 0
         else:
-            offset = offset.seconds / 60
+            offset = offset.days * 24 * 60 + offset.seconds / 60
         wldict['tzoffset'] = offset
         wldict['i18n'] = i18n_enabled
         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/Change #10424 (Replace propriatary tz handling)




Change Properties
Action