"Unexpected error" in trac-post-commit-hook while adding more than one ticket/s
|Reported by:||Owned by:|
I found a bug in trac-post-commit-hook, when used scripted, a script can call trac-post-commit-hook more than one time per second, on the same ticket, if we do so :
One line 183 :
ticket.save_changes(self.author, self.msg, self.now, db, cnum+1)
Will fail as self.now is datetime.now(utc) (line 156) with a database error (as i run mysql i got):
Unexpected error while processing ticket ID 98: (1062, "Duplicate entry '98-1295877592-comment' for key 1")
Note that 1062 is just the mysql error number for duplicate entry.
I have two possible and combinable fixes to propose :
- while catching the duplicate entry exception, just increment the timestamp by one, and retry (more than one time, as i can create more than 2 tickets by seconds :-) )
- Propose an optional parameter to the script to force the time so the time can be set to the real comment time (as, when i push 10 tickts / seconds, it's from a queue and each have not been written the same second) which will less suposed to conflict (but which can).