Search code examples
tracgithooks

post-receive hook fails to update Trac ticket upon push with several commits for the same ticket


There is a Trac 0.11.7 environment, which is integrated with a Git repository using GitPlugin. This repository has a post-receive hook, which is a copy of the one provided by the GitPlugin team.

The post-receive hook is triggered when developers push their changes to the server. If the pack contains one commit per tiket then everything works perfectly -- individual commit messages are associated with respective tickets.

However, if there are several commits for the same ticket then only the latest commit gets associated with a ticket, with the following error for the rest of commits:

Unexpected error while processing ticket ID 1: columns ticket, time, field are not unique

The hook (written in python) has been analysed, and it would appear that the time portion of the argument now of the call ticket.save_changes(eml, msg, now, db, cnum + 1) in function handle_commit differs only by milliseconds for sequentially processed commits.

The database used for Trac is SQLite, which most likely does not handle milliseconds as part of the date/time type.

What would be a good and easy solution to resolve the above situation?


Solution

  • To overcome exactly that limitation caused by automated submissions, i.e. the BatchModifyPlugin triggered that as well, the internal Trac time stamp format has been changed in 0.12 from POSIX seconds to POSIX microseconds (since 1970-01-01 0:00).

    So the best solution is an upgrade to Trac 0.12.3. The other way, as suggested by 01es is to mess around with the plugin instead. Sorry, but this is just a hack to the hack that is not to be blamed for the issue. Even the minimal interval between the automated commits will be enough to let your issue disappear as soon as you start to deploy the current stable Trac version.