Modify

Opened 12 years ago

Closed 11 years ago

Last modified 9 years ago

#10207 closed defect (duplicate)

Cannot update a ticket while changing child ticket to parent ticket (and vice versa) with a 'comment'.

Reported by: anonymous Owned by: Ryan J Ollos
Priority: normal Component: MasterTicketsPlugin
Severity: normal Keywords:
Cc: Trac Release: 0.12

Description (last modified by Ryan J Ollos)

While changing child ticket to parent ticket in a ticket ,If we give some comment and submit both then there is no update in ticket and There is Integrity Error

IntegrityError: columns ticket, time, field are not unique

File "C:/SDWorkbenchServer/python/lib/site-packages/trac-0.12.2-py2.7.egg/trac/web/main.py", line 511, in _dispatch_request
  dispatcher.dispatch(req)
File "C:/SDWorkbenchServer/python/lib/site-packages/trac-0.12.2-py2.7.egg/trac/web/main.py", line 237, in dispatch
  resp = chosen_handler.process_request(req)
File "C:/SDWorkbenchServer/python/lib/site-packages/trac-0.12.2-py2.7.egg/trac/ticket/web_ui.py", line 169, in process_request
  return self._process_ticket_request(req)
File "C:/SDWorkbenchServer/python/lib/site-packages/trac-0.12.2-py2.7.egg/trac/ticket/web_ui.py", line 541, in _process_ticket_request
  self._do_save(req, ticket, action)
File "C:/SDWorkbenchServer/python/lib/site-packages/trac-0.12.2-py2.7.egg/trac/ticket/web_ui.py", line 1238, in _do_save
  cnum=internal_cnum):
File "C:/SDWorkbenchServer/python/lib/site-packages/trac-0.12.2-py2.7.egg/trac/ticket/model.py", line 360, in save_changes
  listener.ticket_changed(self, comment, author, old_values)
File "C:/SDWorkbenchServer/python/lib/site-packages/tracmastertickets-3.0.2-py2.7.egg/mastertickets/api.py", line 120, in ticket_changed
  links.save(author, comment, tkt.time_changed, db)
File "C:/SDWorkbenchServer/python/lib/site-packages/tracmastertickets-3.0.2-py2.7.egg/mastertickets/model.py", line 83, in save
  (n, when_ts, author, 'comment', '', '(In #%s) %s'%(self.tkt.id, comment)))
File "C:/SDWorkbenchServer/python/lib/site-packages/trac-0.12.2-py2.7.egg/trac/db/util.py", line 65, in execute
  return self.cursor.execute(sql_escape_percent(sql), args)
File "C:/SDWorkbenchServer/python/lib/site-packages/trac-0.12.2-py2.7.egg/trac/db/sqlite_backend.py", line 78, in execute
  result = PyFormatCursor.execute(self, *args)
File "C:/SDWorkbenchServer/python/lib/site-packages/trac-0.12.2-py2.7.egg/trac/db/sqlite_backend.py", line 56, in execute
  args or [])
File "C:/SDWorkbenchServer/python/lib/site-packages/trac-0.12.2-py2.7.egg/trac/db/sqlite_backend.py", line 48, in _rollback_on_error
  return function(self, *args, **kwargs)

Attachments (1)

model.py (5.4 KB) - added by anonymous 12 years ago.
Modified file

Download all attachments as: .zip

Change History (7)

comment:1 Changed 12 years ago by anonymous

When we updating parent/child ticket with comment , the logic (for loop) was iterating 2 times to modify "parent field" and "child field" each in model.py . Each time while modifying if comment is given in field , it was updating that also. In first iteration the comment field was modified so in second iteration while changing it was throwing error. By making comment field to change only in one time, we can prevent the error. check out modified script(model.py) as attachment.

Changed 12 years ago by anonymous

Attachment: model.py added

Modified file

comment:2 Changed 12 years ago by Ryan J Ollos

Description: modified (diff)

comment:3 Changed 11 years ago by Ryan J Ollos

Unified diff is the preferred format for a patch. If I diff against the latest revision of model.py, I get:

  • model.py

    old new  
    1 import copy
     1# Created by Noah Kantrowitz on 2007-07-04.
     2# Copyright (c) 2007 Noah Kantrowitz. All rights reserved.
     3import copy
    24from datetime import datetime
    35
    46from trac.ticket.model import Ticket
     
    79
    810class TicketLinks(object):
    911    """A model for the ticket links used MasterTickets."""
    10    
     12
    1113    def __init__(self, env, tkt, db=None):
    1214        self.env = env
    1315        if not isinstance(tkt, Ticket):
     
    4648            (new_blocked_by, self._old_blocked_by, 'blocking', ('dest', 'source')),
    4749        ]
    4850       
    49         comment_enable_flag = True
    5051        for new_ids, old_ids, field, sourcedest in to_check:
    5152            for n in new_ids | old_ids:
    5253                update_field = None
     
    7071                    cursor.execute('INSERT INTO ticket_change (ticket, time, author, field, oldvalue, newvalue) VALUES (%s, %s, %s, %s, %s, %s)',
    7172                                   (n, when_ts, author, field, old_value, new_value))
    7273                                   
    73                     if comment and comment_enable_flag == True: # comment field shound modify once even for multiple changes
     74                    if comment:
    7475                        cursor.execute('INSERT INTO ticket_change (ticket, time, author, field, oldvalue, newvalue) VALUES (%s, %s, %s, %s, %s, %s)',
    7576                                       (n, when_ts, author, 'comment', '', '(In #%s) %s'%(self.tkt.id, comment)))
    76                         comment_enable_flag = False
     77                                 
    7778                           
    7879                    cursor.execute('UPDATE ticket_custom SET value=%s WHERE ticket=%s AND name=%s',
    7980                                   (new_value, n, field))
     
    8485                    if not cursor.rowcount:
    8586                        cursor.execute('INSERT INTO ticket_custom (ticket, name, value) VALUES (%s, %s, %s)',
    8687                                       (n, field, new_value))
    87        
     88       
     89        # cursor.execute('DELETE FROM mastertickets WHERE source=%s OR dest=%s', (self.tkt.id, self.tkt.id))
     90        # data = []
     91        # for tkt in self.blocking:
     92        #     if isinstance(tkt, Ticket):
     93        #         tkt = tkt.id
     94        #     data.append((self.tkt.id, tkt))
     95        # for tkt in self.blocked_by:
     96        #     if isisntance(tkt, Ticket):
     97        #         tkt = tkt.id
     98        #     data.append((tkt, self.tkt.id))
     99        #
     100        # cursor.executemany('INSERT INTO mastertickets (source, dest) VALUES (%s, %s)', data)
    88101       
    89102        if handle_commit:
    90103            db.commit()
     
    105118               (self.tkt.id, l(getattr(self, 'blocking', [])), l(getattr(self, 'blocked_by', [])))
    106119
    107120    @staticmethod
    108     def walk_tickets(env, tkt_ids):
     121    def walk_tickets(env, tkt_ids, full=False):
    109122        """Return an iterable of all links reachable directly above or below those ones."""
    110         def visit(tkt, memo, next_fn):
     123        def visit(tkt, memo, next_fn, full=False):
    111124            if tkt in memo:
    112125                return False
    113126           
     
    120133        memo1 = {}
    121134        memo2 = {}
    122135        for id in tkt_ids:
    123             visit(id, memo1, lambda links: links.blocking)
    124             visit(id, memo2, lambda links: links.blocked_by)
     136            if full:
     137                visit(id, memo1, lambda links: links.blocking|links.blocked_by)
     138            else:
     139                visit(id, memo1, lambda links: links.blocking)
     140                visit(id, memo2, lambda links: links.blocked_by)
    125141        memo1.update(memo2)
    126142        return memo1.itervalues()

comment:4 Changed 11 years ago by Ryan J Ollos

Owner: changed from Noah Kantrowitz to Ryan J Ollos
Status: newassigned

comment:5 Changed 11 years ago by Ryan J Ollos

Summary: Cannot update a ticket while changing child ticket to patent ticket(and vice versa) with a 'comment'.Cannot update a ticket while changing child ticket to parent ticket (and vice versa) with a 'comment'.

comment:6 Changed 11 years ago by Ryan J Ollos

Resolution: duplicate
Status: assignedclosed

It looks like my diff in comment:3 is backwards. Anyway, Duplicate of #10194.

Last edited 9 years ago by Ryan J Ollos (previous) (diff)

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Ryan J Ollos.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.