Modify

Opened 7 years ago

Closed 4 years ago

#2269 closed defect (fixed)

Notification error using 0.11-dev and xmlrpc trunk

Reported by: mayer@… Owned by: osimons
Priority: high Component: XmlRpcPlugin
Severity: normal Keywords:
Cc: thijs 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 7 years ago by 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 7 years ago by athomas

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 7 years ago by 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 7 years ago by athomas

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

comment:5 Changed 7 years ago by 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 7 years ago by 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 7 years ago by 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 7 years ago by athomas

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

comment:9 Changed 7 years ago by athomas

  • Resolution set to fixed
  • Status changed from new to closed

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

comment:10 follow-up: Changed 5 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 5 years ago by anonymous

  • Resolution fixed deleted
  • Status changed from closed to reopened

comment:12 Changed 4 years ago by thijs

  • Cc thijs added
  • Owner changed from athomas to osimons
  • Status changed from reopened to new

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

  • Resolution set to fixed
  • Status changed from new to closed

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.

Add Comment

Modify Ticket

Action
as closed .
The resolution will be deleted. Next status will be 'reopened'.
Author


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

 
Note: See TracTickets for help on using tickets.