Ticket #2269 (closed defect: fixed)

Opened 1 year ago

Last modified 2 weeks ago

Notification error using 0.11-dev and xmlrpc trunk

Reported by: mayer@couga.net Assigned to: athomas
Priority: high Component: XmlRpcPlugin
Severity: normal Keywords:
Cc: 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

Change History

12/07/07 10:06:46 changed by mayer@couga.net

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.

12/07/07 10:16:38 changed by athomas

Try this diff:

Index: trunk/tracrpc/ticket.py
===================================================================
--- trunk/tracrpc/ticket.py	(revision 2855)
+++ trunk/tracrpc/ticket.py	(working copy)
@@ -8,7 +8,7 @@
 from trac.ticket.api import TicketSystem
 from trac.ticket.notification import TicketNotifyEmail
 
-import time
+from datetime import datetime
 import inspect
 import xmlrpclib
 from StringIO import StringIO
@@ -96,7 +96,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()
 
         t = model.Ticket(self.env, id)
         for k, v in attributes.iteritems():

12/07/07 10:28:16 changed by mayer@couga.net

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

12/07/07 10:34:15 changed by athomas

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

12/07/07 10:43:32 changed by mayer@couga.net

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

12/07/07 18:59:42 changed by mayer@couga.net

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.

12/07/07 19:21:21 changed by mayer@couga.net

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():

12/07/07 22:04:34 changed by athomas

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

12/07/07 22:11:34 changed by athomas

  • status changed from new to closed.
  • resolution set to fixed.

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


Add/Change #2269 (Notification error using 0.11-dev and xmlrpc trunk)




Change Properties
Action