Opened 12 years ago
Closed 9 years ago
#10251 closed defect (fixed)
Unable to upgrade OS X tracd 0.11.7 database
Reported by: | Sam Halliday | Owned by: | Ryan J Ollos |
---|---|---|---|
Priority: | normal | Component: | WorkLogPlugin |
Severity: | normal | Keywords: | |
Cc: | Trac Release: | 0.11 |
Description (last modified by )
I get the following exception when attempting to upgrade the TRAC install, with a similar thing when I go to any issue:
$ trac-admin /Users/samuel/Desktop/TRAC/test upgrade Traceback (most recent call last): File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/trac-admin", line 8, in <module> load_entry_point('Trac==0.11.7', 'console_scripts', 'trac-admin')() File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Trac-0.11.7-py2.7.egg/trac/admin/console.py", line 1321, in run return admin.onecmd(command) File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Trac-0.11.7-py2.7.egg/trac/admin/console.py", line 138, in onecmd rv = cmd.Cmd.onecmd(self, line) or 0 File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/cmd.py", line 221, in onecmd return func(arg) File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Trac-0.11.7-py2.7.egg/trac/admin/console.py", line 1154, in do_upgrade if not self.__env.needs_upgrade(): File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Trac-0.11.7-py2.7.egg/trac/env.py", line 435, in needs_upgrade for participant in self.setup_participants: File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Trac-0.11.7-py2.7.egg/trac/core.py", line 70, in extensions return filter(None, [component.compmgr[cls] for cls in extensions]) File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Trac-0.11.7-py2.7.egg/trac/core.py", line 207, in __getitem__ component = cls(self) File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Trac-0.11.7-py2.7.egg/trac/core.py", line 111, in maybe_init init(self) File "build/bdist.macosx-10.8-x86_64/egg/worklog/api.py", line 36, in __init__ AttributeError: 'Environment' object has no attribute 'get_read_db'
Attachments (0)
Change History (11)
comment:1 Changed 12 years ago by
comment:2 Changed 12 years ago by
Description: | modified (diff) |
---|
comment:3 Changed 12 years ago by
Owner: | changed from Colin Guthrie to Ryan J Ollos |
---|
In [11830] I renamed 0.12
to trunk
and made the comment that the 0.11
and 0.12
branches were equivalent. Looking at it now, however, I see that is not the case. I must have done something stupid, like diff 0.11 0.12
without the -r
flag. I'll fix this now.
comment:4 Changed 12 years ago by
Here is the 0.11 and 0.12 diff @ r11829:
-
setup.py
Only in 0.11: setup.cfg diff -ru 0.11/setup.py 0.12/setup.py
old new 7 7 setup(name=PACKAGE, 8 8 description='Plugin to manage the which tickets users are currently working on', 9 9 keywords='trac plugin ticket working', 10 version='0. 1',10 version='0.2', 11 11 url='', 12 12 license='http://www.opensource.org/licenses/mit-license.php', 13 13 author='Colin Guthrie', -
worklog/api.py
Only in 0.12/.svn/pristine: 18 Only in 0.11/.svn/pristine: 1f Only in 0.12/.svn/pristine: 4d Only in 0.11/.svn/pristine: 74 Only in 0.11/.svn/pristine: 7f Only in 0.12/.svn/pristine: 85 Only in 0.11/.svn/pristine: aa Only in 0.11/.svn/pristine: b3 Only in 0.12/.svn/pristine: d3 Binary files 0.11/.svn/wc.db and 0.12/.svn/wc.db differ diff -ru 0.11/worklog/api.py 0.12/worklog/api.py
old new 33 33 self.db_installed_version = None 34 34 35 35 # Initialise database schema version tracking. 36 db = self.env.get_ db_cnx()36 db = self.env.get_read_db() 37 37 cursor = db.cursor() 38 38 cursor.execute("SELECT value FROM system WHERE name=%s", (self.db_version_key,)) 39 39 try: 40 40 self.db_installed_version = int(cursor.fetchone()[0]) 41 41 except: 42 self.db_installed_version = 0 43 try: 44 cursor.execute("INSERT INTO system (name,value) VALUES(%s,%s)", 45 (self.db_version_key, self.db_installed_version)) 46 db.commit() 47 except Exception, e: 48 db.rollback() 49 raise e 50 42 @self.env.with_transaction() 43 def do_init(db): 44 cursor = db.cursor() 45 self.db_installed_version = 0 46 cursor.execute("INSERT INTO system (name,value) VALUES(%s,%s)", 47 (self.db_version_key, self.db_installed_version)) 51 48 52 49 def environment_created(self): 53 50 """Called when a new Trac environment is created.""" … … 57 54 def system_needs_upgrade(self): 58 55 return self.db_installed_version < self.db_version 59 56 60 def do_db_upgrade(self ):57 def do_db_upgrade(self, db): 61 58 # Legacy support hack (supports upgrades from revisions r2495 or before) 62 db = self.env.get_db_cnx()63 cursor = db.cursor()64 59 if self.db_installed_version == 0: 65 60 try: 61 cursor = self.env.get_read_db().cursor() 66 62 cursor.execute('SELECT * FROM work_log LIMIT 1') 67 db.commit()68 63 # We've succeeded so we actually have version 1 69 64 self.db_installed_version = 1 70 65 except: 71 db.rollback() 66 cursor.connection.rollback() 67 self.db_installed_version = 0 72 68 # End Legacy support hack 73 69 74 70 # Do the staged updates … … 123 119 # Updates complete, set the version 124 120 cursor.execute("UPDATE system SET value=%s WHERE name=%s", 125 121 (self.db_version, self.db_version_key)) 126 db.commit()127 122 except Exception, e: 128 123 self.log.error("WorklogPlugin Exception: %s" % (e,)); 129 124 db.rollback() … … 132 127 133 128 134 129 def needs_user_man(self): 135 db = self.env.get_ db_cnx()130 db = self.env.get_read_db() 136 131 cursor = db.cursor() 137 132 try: 138 133 cursor.execute('SELECT MAX(version) FROM wiki WHERE name=%s', (user_manual_wiki_title,)) 139 db.commit()140 134 maxversion = int(cursor.fetchone()[0]) 141 135 except: 142 db.rollback()136 cursor.connection.rollback() 143 137 maxversion = 0 144 138 145 139 return maxversion < user_manual_version 146 140 147 def do_user_man_update(self ):141 def do_user_man_update(self, db): 148 142 when = int(time.time()) 149 db = self.env.get_db_cnx()150 143 cursor = db.cursor() 151 144 try: 152 145 cursor.execute('INSERT INTO wiki (name,version,time,author,ipnr,text,comment,readonly) ' … … 176 169 transactions. This is done implicitly after all participants have 177 170 performed the upgrades they need without an error being raised. 178 171 """ 179 def p(s):180 print s181 return True182 172 print "Worklog needs an upgrade" 183 173 if self.system_needs_upgrade(): 184 p("Upgrading Database") 185 self.do_db_upgrade() 174 print " * Upgrading Database" 175 @self.env.with_transaction(db) 176 def real_do_db_upgrade(db): 177 self.do_db_upgrade(db) 186 178 if self.needs_user_man(): 187 p("Upgrading usermanual") 188 self.do_user_man_update() 179 print " * Upgrading usermanual" 180 @self.env.with_transaction(db) 181 def real_do_user_man_update(db): 182 self.do_user_man_update(db) 189 183 print "Done upgrading Worklog" 190 184 191 185 -
worklog/manager.py
diff -ru 0.11/worklog/manager.py 0.12/worklog/manager.py
old new 65 65 # If we get here then we know we can start work :) 66 66 return True 67 67 68 def save_ticket(self, tckt, db,msg):68 def save_ticket(self, tckt, msg): 69 69 # determine sequence number... 70 70 cnum = 0 71 71 tm = TicketModule(self.env) 72 for change in tm.grouped_changelog_entries(tckt, db):72 for change in tm.grouped_changelog_entries(tckt, None): 73 73 if change['permanent']: 74 74 cnum += 1 75 75 nowdt = self.now 76 76 nowdt = to_datetime(nowdt) 77 tckt.save_changes(self.authname, msg, nowdt, db, cnum+1)77 tckt.save_changes(self.authname, msg, nowdt, None, cnum+1) 78 78 ## Often the time overlaps and causes a db error, 79 79 ## especially when the trac integration post-commit hook is used. 80 80 ## NOTE TO SELF. I DON'T THINK THIS IS NECESSARY RIGHT NOW... 81 81 #count = 0 82 82 #while count < 10: 83 83 # try: 84 # tckt.save_changes(self.authname, msg, self.now, db, cnum+1)84 # tckt.save_changes(self.authname, msg, self.now, None, cnum+1) 85 85 # count = 42 86 86 # except Exception, e: 87 87 # self.now += 1 88 88 # count += 1 89 db.commit()90 89 91 90 tn = TicketNotifyEmail(self.env) 92 91 tn.notify(tckt, newticket=0, modtime=nowdt) … … 104 103 # ticket modification. 105 104 106 105 # If the ticket is closed, we need to reopen it. 107 db = self.env.get_db_cnx() 108 tckt = Ticket(self.env, ticket, db) 106 tckt = Ticket(self.env, ticket) 109 107 110 108 if 'closed' == tckt['status']: 111 109 tckt['status'] = 'reopened' 112 110 tckt['resolution'] = '' 113 self.save_ticket(tckt, db,'Automatically reopening in order to start work.')111 self.save_ticket(tckt, 'Automatically reopening in order to start work.') 114 112 115 113 # Reinitialise for next test 116 db = self.env.get_db_cnx() 117 tckt = Ticket(self.env, ticket, db) 114 tckt = Ticket(self.env, ticket) 118 115 119 116 120 117 if self.authname != tckt['owner']: … … 123 120 tckt['status'] = 'accepted' 124 121 else: 125 122 tckt['status'] = 'new' 126 self.save_ticket(tckt, db,'Automatically reassigning in order to start work.')123 self.save_ticket(tckt, 'Automatically reassigning in order to start work.') 127 124 128 125 # Reinitialise for next test 129 db = self.env.get_db_cnx() 130 tckt = Ticket(self.env, ticket, db) 126 tckt = Ticket(self.env, ticket) 131 127 132 128 133 129 if 'accepted' != tckt['status']: 134 130 tckt['status'] = 'accepted' 135 self.save_ticket(tckt, db,'Automatically accepting in order to start work.')131 self.save_ticket(tckt, 'Automatically accepting in order to start work.') 136 132 137 133 # There is a chance the user may be working on another ticket at the moment 138 134 # depending on config options 139 135 if self.config.getbool('worklog', 'autostopstart'): 140 136 # Don't care if this fails, as with these arguments the only failure 141 137 # point is if there is no active task... which is the desired scenario :) 142 self.stop_work( )138 self.stop_work(comment='Stopping work on this ticket to start work on #%s.' % (ticket)) 143 139 self.explanation = '' 144 140 145 cursor = db.cursor() 146 cursor.execute('INSERT INTO work_log (worker, ticket, lastchange, starttime, endtime) ' 147 'VALUES (%s, %s, %s, %s, %s)', 148 (self.authname, ticket, self.now, self.now, 0)) 149 db.commit() 141 @self.env.with_transaction() 142 def do_log(db): 143 cursor = db.cursor() 144 cursor.execute('INSERT INTO work_log (worker, ticket, lastchange, starttime, endtime) ' 145 'VALUES (%s, %s, %s, %s, %s)', 146 (self.authname, ticket, self.now, self.now, 0)) 150 147 return True 151 148 152 149 … … 168 165 169 166 stoptime = float(stoptime) 170 167 171 db = self.env.get_db_cnx();172 cursor = db.cursor()173 cursor.execute('UPDATE work_log '174 'SET endtime=%s, lastchange=%s, comment=%s'175 'WHERE worker=%s AND lastchange=%s AND endtime=0',176 (stoptime, stoptime, comment, self.authname, active['lastchange']))177 db.commit()168 @self.env.with_transaction() 169 def do_log(db): 170 cursor = db.cursor() 171 cursor.execute('UPDATE work_log ' 172 'SET endtime=%s, lastchange=%s, comment=%s ' 173 'WHERE worker=%s AND lastchange=%s AND endtime=0', 174 (stoptime, stoptime, comment, self.authname, active['lastchange'])) 178 175 179 176 plugtne = self.config.getbool('worklog', 'timingandestimation') and self.config.get('ticket-custom', 'hours') 180 177 plughrs = self.config.getbool('worklog', 'trachoursplugin') and self.config.get('ticket-custom', 'totalhours') … … 214 211 if not message: 215 212 message = 'Hours recorded automatically by the worklog plugin.' 216 213 217 db = self.env.get_db_cnx() 218 tckt = Ticket(self.env, active['ticket'], db) 214 tckt = Ticket(self.env, active['ticket']) 219 215 220 216 if plugtne: 221 217 tckt['hours'] = hours 222 self.save_ticket(tckt, db,message)218 self.save_ticket(tckt, message) 223 219 message = '' 224 220 225 221 if message: 226 db = self.env.get_db_cnx() 227 tckt = Ticket(self.env, active['ticket'], db) 228 self.save_ticket(tckt, db, message) 222 tckt = Ticket(self.env, active['ticket']) 223 self.save_ticket(tckt, message) 229 224 230 225 return True 231 226 232 227 233 228 def who_is_working_on(self, ticket): 234 db = self.env.get_ db_cnx()229 db = self.env.get_read_db() 235 230 cursor = db.cursor() 236 231 cursor.execute('SELECT worker,starttime FROM work_log WHERE ticket=%s AND endtime=0', (ticket,)) 237 232 try: … … 248 243 if self.authname == 'anonymous': 249 244 return None 250 245 251 db = self.env.get_ db_cnx()246 db = self.env.get_read_db() 252 247 cursor = db.cursor() 253 248 cursor.execute('SELECT MAX(lastchange) FROM work_log WHERE worker=%s', (self.authname,)) 254 249 row = cursor.fetchone() … … 289 284 return task 290 285 291 286 def get_work_log(self, mode='all'): 292 db = self.env.get_ db_cnx()287 db = self.env.get_read_db() 293 288 cursor = db.cursor() 294 289 if mode == 'user': 295 290 cursor.execute('SELECT wl.worker, s.value, wl.starttime, wl.endtime, wl.ticket, t.summary, t.status, wl.comment ' -
worklog/timeline_hook.py
diff -ru 0.11/worklog/timeline_hook.py 0.12/worklog/timeline_hook.py
old new 34 34 ts_stop = to_timestamp(stop) 35 35 36 36 ticket_realm = Resource('ticket') 37 db = self.env.get_ db_cnx()37 db = self.env.get_read_db() 38 38 cursor = db.cursor() 39 39 40 40 cursor.execute("""SELECT wl.worker,wl.ticket,wl.time,wl.starttime,wl.comment,wl.kind,t.summary,t.status,t.resolution,t.type
comment:5 Changed 12 years ago by
Status: | new → assigned |
---|
comment:6 Changed 12 years ago by
(In [12089]) Refs #10206, #10251:
- Made the
trunk
compatible with Trac 0.11, by rolling out changes introduced in [9480] and later. There is nothing forcing us to adapt to the new Trac DB API at the moment, and it is easier to maintain a single code-base that is compatible back to Trac 0.11. The Trac DB API changed again in 1.0, so we are better off waiting and adapting to that API down the road anyway. - Attempted to cleanup the mess of
import
statements in every module. Modified theentry_points
to adapt to these changes. - Made the
XmlRpc
lib an optional component. There is more work to do here still.
comment:7 Changed 12 years ago by
(In [12090]) Refs #10206, #10251:
- Renamed
timeline_hook.py
totimeline.py
, with the goal of making the source code layout match the standard for Trac plugins. - Fixed an error introduced in [12089] due to a missing
import
.
As in [12088], if your trac.ini
file specifies the individual components to enable, you'll have to make the following change:
worklog.timeline_hook.worklogtimelineaddon = enabled
->
worklog.timeline.worklogtimelineeventprovider = enabled
comment:8 Changed 12 years ago by
What the plugin needs now is someone to do more thorough testing than I've had time for. I would greatly appreciate the effort, and you can expect rapid follow-up and resolution of any issues that are found, within hours or a day at the most.
comment:9 Changed 12 years ago by
Thanks for this rjollos, but I never got to follow up when TH was down to say that I've now migrated to trac 1.0 :-)
comment:10 Changed 12 years ago by
Status: | assigned → new |
---|
comment:11 Changed 9 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
I won't be doing any more work to support Trac < 1.0.
I went back to r10794, 0.11 branch, and this works ok.