Opened 12 years ago

Last modified 3 years ago

#10194 new defect

Cannot update a ticket using trac.ticket.model.save_changes with both a 'comment' and a 'when' field. — at Initial Version

Reported by: François Granade Owned by: Noah Kantrowitz
Priority: normal Component: MasterTicketsPlugin
Severity: normal Keywords:
Cc: Jun Omae, falkb Trac Release: 0.12

Description

This was found in the TicketImportPlugin, see #10188, and took me some time to debug. The following piece of code (given and "env" environment):

 	        from trac.ticket.web_ui import Ticket 
 	        from datetime import datetime 
 	        from trac.util.datefmt import utc 
 	        ticket = Ticket(env) 
 	        ticket['summary'] = 'The summary' 
 	        ticket.insert() 
 	        ticket['blockedby'] = str(ticket.id) 
 	        ticket.save_changes('someone',comment='Some comments', when=datetime.now(utc)) 

will work if the MasterTicketsPlugin is not installed, but will fail if it is installed, with the following error:

    ticket.save_changes('someone','Some comments', when=datetime.now(utc))
  File "/Users/francois/ticketimportplugin/0.11/env2.5/lib/python2.5/site-packages/Trac-0.12-py2.5.egg/trac/ticket/model.py", line 353, in save_changes
    listener.ticket_changed(self, comment, author, old_values)
  File "build/bdist.macosx-10.7-x86_64/egg/mastertickets/api.py", line 111, in ticket_changed
    links.save(author, comment, tkt.time_changed, db)
  File "build/bdist.macosx-10.7-x86_64/egg/mastertickets/model.py", line 76, in save
    (n, when_ts, author, 'comment', '', '(In #%s) %s'%(self.tkt.id, comment)))
  File "/Users/francois/ticketimportplugin/0.11/env2.5/lib/python2.5/site-packages/Trac-0.12-py2.5.egg/trac/db/util.py", line 65, in execute
    return self.cursor.execute(sql_escape_percent(sql), args)
  File "/Users/francois/ticketimportplugin/0.11/env2.5/lib/python2.5/site-packages/Trac-0.12-py2.5.egg/trac/db/sqlite_backend.py", line 79, in execute
    result = PyFormatCursor.execute(self, *args)
  File "/Users/francois/ticketimportplugin/0.11/env2.5/lib/python2.5/site-packages/Trac-0.12-py2.5.egg/trac/db/sqlite_backend.py", line 57, in execute
    args or [])
  File "/Users/francois/ticketimportplugin/0.11/env2.5/lib/python2.5/site-packages/Trac-0.12-py2.5.egg/trac/db/sqlite_backend.py", line 48, in _rollbac\
k_on_error
    return function(self, *args, **kwargs)
IntegrityError: columns ticket, time, field are not unique

See browser:ticketimportplugin/0.11/talm_importer/test.py@11805#L460

Change History (0)

Note: See TracTickets for help on using tickets.