Modify

Opened 17 years ago

Closed 14 years ago

#2269 closed defect (fixed)

Notification error using 0.11-dev and xmlrpc trunk

Reported by: Daniel Mayer Owned by: osimons
Priority: high Component: XmlRpcPlugin
Severity: normal Keywords:
Cc: Thijs Triemstra Trac Release: 0.11

Description

Hi,

using Trac 0.11-dev (r6280) and the xmlrpc plugin (trunk) notifications cannot be send after changes to a ticket are comittet (using mylyn in my case). The traceback in the logfile is provided below and its coming down to a wrong format of the "now" time which is passed on to the TracNotifier.
Notifications when changing a ticket through the webinterface work perfectly.

2007-12-05 03:06:29,257 Trac[__init__] ERROR: Failure sending notification on change of ticket #26: unsupported operand type(s) for -: 'float' and 'datetime.datetime'
Traceback (most recent call last):
  File "/usr/lib/python2.4/site-packages/TracXMLRPC-1.0.0-py2.4.egg/tracrpc/ticket.py", line 109, in update
    tn.notify(t, newticket=False, modtime=now)
  File "/usr/lib/python2.4/site-packages/Trac-0.11dev_r6280-py2.4.egg/trac/ticket/notification.py", line 81, in notify
    for change in TicketModule(self.env).grouped_changelog_entries(
  File "/usr/lib/python2.4/site-packages/Trac-0.11dev_r6280-py2.4.egg/trac/ticket/web_ui.py", line 1253, in grouped_changelog_entries
    changelog = ticket.get_changelog(when=when, db=db)
  File "/usr/lib/python2.4/site-packages/Trac-0.11dev_r6280-py2.4.egg/trac/ticket/model.py", line 286, in get_changelog
    when_ts = when and to_timestamp(when) or 0
  File "/usr/lib/python2.4/site-packages/Trac-0.11dev_r6280-py2.4.egg/trac/util/datefmt.py", line 55, in to_timestamp
    diff = dt - _epoc
TypeError: unsupported operand type(s) for -: 'float' and 'datetime.datetime'

Attachments (0)

Change History (13)

comment:1 Changed 17 years ago by Daniel Mayer

If somebody could point me in a direction on how the timestamp 'now' in ticket.py has to be converted (to which object or type) in order to be conform to the Trac-API and therefore be understood by /trac/util/datefmt.py I would be happy to implement this. This I a major issue for us using the Plugin because other developer rely on the notifications. I know that the 0.11 interface is not complete yet.

comment:2 Changed 17 years ago by Alec Thomas

Try this diff:

  • trunk/tracrpc/ticket.py

     
    88from trac.ticket.api import TicketSystem
    99from trac.ticket.notification import TicketNotifyEmail
    1010
    11 import time
     11from datetime import datetime
    1212import inspect
    1313import xmlrpclib
    1414from StringIO import StringIO
     
    9696
    9797    def update(self, req, id, comment, attributes = {}, notify=False):
    9898        """ Update a ticket, returning the new ticket in the same form as getTicket(). """
    99         now = time.time()
     99        now = datetime.now()
    100100
    101101        t = model.Ticket(self.env, id)
    102102        for k, v in attributes.iteritems():

comment:3 Changed 17 years ago by Daniel Mayer

Improved the situation but I get now:

2007-12-07 17:06:05,057 Trac[__init__] ERROR: Failure sending notification on change of ticket #40: can't subtract offset-naive and offset-aware datetimes
Traceback (most recent call last):
  File "/usr/lib/python2.4/site-packages/TracXMLRPC-1.0.0-py2.4.egg/tracrpc/ticket.py", line 109, in update
    tn.notify(t, newticket=False, modtime=now)
  File "/usr/lib/python2.4/site-packages/Trac-0.11dev_r6285-py2.4.egg/trac/ticket/notification.py", line 81, in notify
    for change in TicketModule(self.env).grouped_changelog_entries(
  File "/usr/lib/python2.4/site-packages/Trac-0.11dev_r6285-py2.4.egg/trac/ticket/web_ui.py", line 1253, in grouped_changelog_entries
    changelog = ticket.get_changelog(when=when, db=db)
  File "/usr/lib/python2.4/site-packages/Trac-0.11dev_r6285-py2.4.egg/trac/ticket/model.py", line 286, in get_changelog
    when_ts = when and to_timestamp(when) or 0
  File "/usr/lib/python2.4/site-packages/Trac-0.11dev_r6285-py2.4.egg/trac/util/datefmt.py", line 55, in to_timestamp
    diff = dt - _epoc
TypeError: can't subtract offset-naive and offset-aware datetimes

comment:4 Changed 17 years ago by Alec Thomas

Try changing .now() to .utcnow().

comment:5 Changed 17 years ago by Daniel Mayer

I changed the update funtction to

    def update(self, req, id, comment, attributes = {}, notify=False):
        """ Update a ticket, returning the new ticket in the same form as getTicket(). """
        now = datetime.utcnow()

does not change anything

2007-12-07 17:38:57,288 Trac[__init__] ERROR: Failure sending notification on change of ticket #40: can't subtract offset-naive and offset-aware datetimes
Traceback (most recent call last):
  File "/usr/lib/python2.4/site-packages/TracXMLRPC-1.0.0-py2.4.egg/tracrpc/ticket.py", line 109, in update
    tn.notify(t, newticket=False, modtime=now)
  File "/usr/lib/python2.4/site-packages/Trac-0.11dev_r6285-py2.4.egg/trac/ticket/notification.py", line 81, in notify
    for change in TicketModule(self.env).grouped_changelog_entries(
  File "/usr/lib/python2.4/site-packages/Trac-0.11dev_r6285-py2.4.egg/trac/ticket/web_ui.py", line 1253, in grouped_changelog_entries
    changelog = ticket.get_changelog(when=when, db=db)
  File "/usr/lib/python2.4/site-packages/Trac-0.11dev_r6285-py2.4.egg/trac/ticket/model.py", line 286, in get_changelog
    when_ts = when and to_timestamp(when) or 0
  File "/usr/lib/python2.4/site-packages/Trac-0.11dev_r6285-py2.4.egg/trac/util/datefmt.py", line 55, in to_timestamp
    diff = dt - _epoc
TypeError: can't subtract offset-naive and offset-aware datetimes

comment:6 Changed 17 years ago by Daniel Mayer

I assume the solution is to give the now() function the timezone it should assume.

e.g. datetime.now(utc) or datetime.now(localtz)

I am not sure which one is the correct one though. I will try it with the UTC and see if i will run in some time-deviations. Hope that helps.

comment:7 Changed 17 years ago by Daniel Mayer

so i think this fixes it completely. Here is the new diff to trunk:

--- trunk/tracrpc/ticket.py	(revision 2626)
+++ trunk/tracrpc/ticket.py	(working copy)
@@ -7,8 +7,10 @@
 import trac.ticket.query as query
 from trac.ticket.api import TicketSystem
 from trac.ticket.notification import TicketNotifyEmail
+from trac.util.datefmt import utc, to_timestamp
 
-import time
+
+from datetime import datetime
 import inspect
 import xmlrpclib
 from StringIO import StringIO
@@ -96,7 +98,7 @@
 
     def update(self, req, id, comment, attributes = {}, notify=False):
         """ Update a ticket, returning the new ticket in the same form as getTicket(). """
-        now = time.time()
+        now = datetime.now(utc)
 
         t = model.Ticket(self.env, id)
         for k, v in attributes.iteritems():

comment:8 Changed 17 years ago by Alec Thomas

Thanks! I had a suspicion that datetime.utcnow() wouldn't work :(

comment:9 Changed 17 years ago by Alec Thomas

Resolution: fixed
Status: newclosed

(In [2857]) Fixed #2269, thanks mayer.

comment:10 Changed 15 years ago by ar@…

The changes made to resolve this issue are not in the latest trunk version. The import datetime from datetime is gone in some commit. So i reopen this issue now if it is ok.

comment:11 Changed 15 years ago by anonymous

Resolution: fixed
Status: closedreopened

comment:12 Changed 15 years ago by Thijs Triemstra

Cc: Thijs Triemstra added; anonymous removed
Owner: changed from Alec Thomas to osimons
Status: reopenednew

comment:13 in reply to:  10 Changed 14 years ago by osimons

Resolution: fixed
Status: newclosed

Replying to ar@anrichter.net:

The changes made to resolve this issue are not in the latest trunk version. The import datetime from datetime is gone in some commit. So i reopen this issue now if it is ok.

No need. Currently a Trac util function is used instead, and now = to_datetime(None, utc) does the same thing.

Re-closing ticket.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain osimons.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


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

 
Note: See TracTickets for help on using tickets.