Opened 7 years ago

# TracBack does not need to be inserted when ticket is already referenced in a log message containing multiple ticket references

Reported by: Owned by: Ryan J Ollos Ryan J Ollos normal TracBacksPlugin normal Chris Nelson 0.11

### Description

If a log message references two tickets, e.g. ticket #100 and ticket #200, then the trac-post-commit-hook inserts the log message into ticket 100 and ticket 200. TracBacksPlugin then inserts a message into ticket 100 saying it was referenced in ticket 200, and vice-versa.

We should make TracBacksPlugin smart enough to know when a reference has already been inserted into a ticket so that we don't get duplicate log messages inserted into tickets.

### comment:1 Changed 7 years ago by Ryan J Ollos

Owner: changed from Mel Chua to Ryan J Ollos

Reassigning to new maintainer.

### comment:2 Changed 4 years ago by Chris Nelson

This has become a high-priority item for us. I'm exploring options to solve it. Do you have any thoughts?

One idea I had was to expose a function to suspend tracbacks for an update. Either:

oldTB = setTBstate(disabled)
ticket.save_changes(...)
setTBstate(oldTB)


Or

tbIgnoreUpdate(ticket.save_changes())


(or something like that which took a function as an argument, disabled tracback, executed the function, then put tracback back.

### comment:3 Changed 4 years ago by Chris Nelson

Cc: Chris Nelson added; anonymous removed

### comment:4 Changed 4 years ago by Chris Nelson

What do you think of this patch?:

• ## 0.11/tracbacks/tracbacks.py

 a class TracBacksPlugin(Component): tickets_referenced = pattern.findall(comment) # convert from strings to ints and discard duplicates tickets_referenced = set(int(t) for t in tickets_referenced) # remove possible self-reference tickets_referenced.discard(ticket.id) # put trackbacks on the tickets that we found if not ticket.id in tickets_referenced \   # not part of a commit and not self.is_tracback(comment): # prevent infinite recursion if not self.is_tracback(comment): # prevent infinite recursion for ticket_to_tracback in tickets_referenced: try: linked_ticket = Ticket(self.env, ticket_to_tracback)

The idea is that it seems quite unlikely that a user would enter a comment into ticket A like "This affects A and B" (The user would say, "This affects this ticket and B".) so we can reasonably assume such text comes from outside, such as a commit hook which will already be updating each ticket so the TB isn't needed.

### Modify Ticket

Action
as new The owner will remain Ryan J Ollos.