Modify ↓
Opened 15 years ago
Closed 14 years ago
#6421 closed defect (duplicate)
[PATCH] Postgres: Saving changes to tickets blocking/blockedby violates an integrity constraint.
Reported by: | Owned by: | Noah Kantrowitz | |
---|---|---|---|
Priority: | normal | Component: | MasterTicketsPlugin |
Severity: | normal | Keywords: | |
Cc: | Trac Release: | 0.11 |
Description
The web browser just shows Postgres's unhelpful "transaction aborted" error message with a traceback.
Here's the originating error, a traceback from trac.log:
2010-01-12 18:16:32,878 Trac[main] ERROR: duplicate key value violates unique constraint "ticket_change_pkey" Traceback (most recent call last): File "/usr/lib/python2.6/dist-packages/trac/web/main.py", line 423, in _dispatch_request dispatcher.dispatch(req) File "/usr/lib/python2.6/dist-packages/trac/web/main.py", line 197, in dispatch resp = chosen_handler.process_request(req) File "/usr/lib/python2.6/dist-packages/trac/ticket/web_ui.py", line 170, in process_request return self._process_ticket_request(req) File "/usr/lib/python2.6/dist-packages/trac/ticket/web_ui.py", line 494, in _process_ticket_request self._do_save(req, ticket, action) File "/usr/lib/python2.6/dist-packages/trac/ticket/web_ui.py", line 989, in _do_save cnum=internal_cnum): File "/usr/lib/python2.6/dist-packages/trac/ticket/model.py", line 282, in save_changes listener.ticket_changed(self, comment, author, old_values) File "build/bdist.macosx-10.6-universal/egg/mastertickets/api.py", line 105, in ticket_changed links.save(author, comment, tkt.time_changed, db) File "build/bdist.macosx-10.6-universal/egg/mastertickets/model.py", line 69, in save (n, when_ts, author, field, old_value, new_value)) File "/usr/lib/python2.6/dist-packages/trac/db/util.py", line 50, in execute return self.cursor.execute(sql_escape_percent(sql), args) File "/usr/lib/python2.6/dist-packages/trac/db/util.py", line 50, in execute return self.cursor.execute(sql_escape_percent(sql), args) IntegrityError: duplicate key value violates unique constraint "ticket_change_pkey"
Here's my patch, made against [7387]:
Index: 0.11/mastertickets/model.py =================================================================== --- 0.11/mastertickets/model.py (revision 7387) +++ 0.11/mastertickets/model.py (working copy) @@ -27,7 +27,7 @@ self.blocked_by = set([num for num, in cursor]) self._old_blocked_by = copy.copy(self.blocked_by) - def save(self, author, comment='', when=None, db=None): + def save(self, author, comment=None, when=None, db=None): """Save new links.""" if when is None: when = datetime.now(utc) @@ -69,8 +69,14 @@ (n, when_ts, author, field, old_value, new_value)) if comment: - cursor.execute('INSERT INTO ticket_change (ticket, time, author, field, oldvalue, newvalue) VALUES (%s, %s, %s, %s, %s, %s)', - (n, when_ts, author, 'comment', '', '(In #%s) %s'%(self.tkt.id, comment))) + comment_text = '(In #%s) %s' % (self.tkt.id, comment) + cursor.execute('SELECT newvalue FROM ticket_change WHERE ticket=%s AND time=%s AND author=%s AND field=%s', (n, when_ts, author, 'comment')) + if cursor.rowcount: + new_value = cursor.fetchone()[0] + '\n\n' + comment_text + cursor.execute('UPDATE ticket_change SET newvalue=%s WHERE ticket=%s AND time=%s AND author=%s AND field=%s', (comment_text, n, when_ts, author, 'comment')) + else: + cursor.execute('INSERT INTO ticket_change (ticket, time, author, field, oldvalue, newvalue) VALUES (%s, %s, %s, %s, %s, %s)', + (n, when_ts, author, 'comment', '', comment_text)) cursor.execute('UPDATE ticket_custom SET value=%s WHERE ticket=%s AND name=%s',
This fixes the problem for the postgres backend, but I have not tested whether it breaks sqlite.
Attachments (0)
Change History (2)
comment:1 Changed 14 years ago by
comment:2 Changed 14 years ago by
Resolution: | → duplicate |
---|---|
Status: | new → closed |
Note: See
TracTickets for help on using
tickets.
Isn't this a duplicate of #2658?
Fixed in MasterTickets 3.0 for Trac 0.12. See:
http://github.com/nielx/trac-mastertickets/commit/ae03a927c629cc1df790b261202e2efea1da1805