id,summary,reporter,owner,description,type,status,priority,component,severity,resolution,keywords,cc,release
7504,'Cannot operate on a closed cursor' exception causes db to appear as if upgrade is needed,abeld,athomas,I'm trying to configure an existing Trac instance to work from under virtualenv (trac 0.12 with SQLite_ wsgi and apache). I ran into a  situation where_ after running `trac-admin /path/to/env upgrade` and wiki upgrade_ trac_ when being called by the webserver says that I have to run the upgrade (i.e. shows an error page to this effect). Running upgrade again on the command line says ''no upgrade necessary''. That is_ running trac from command-line and having it called from the webserver (via wsgi) gives two different results to the ''need to be upgraded?'' question.\r\n\r\nI managed to track this down to the fact that !TagModelProvider's `environment_needs_upgrade` returns ''True'' when being called from wsgi_ and ''False'' when being called from the console. The problem appears to be that the `cursor.execute('select count(*) from tags' )` line in there throws an exception_ but not because the db is old_ but because ''Cannot operate on a closed cursor''.\r\n\r\nMoving the `cursor = db.cursor()` line to below the 'if self._need_migration(db)'_ ie. to just above the try/except appears to solve this issue.\r\n\r\nSo_ suggestions:\r\n 1. the ''except:'' line in environment_needs_upgrade() shouldn't be so greedy_ i.e. it shouldn't swallow all exceptions (if possible to filter out those caused by an old database)\r\n 1. the 'cursor=db.cursor()' line should be moved to just above where it is first used.\r\n\r\nNote that I assume the situation I ran into would be very difficult to reproduce_ but the suggestions above won't have any drawbacks_ and just help make the code cleaner.,defect,closed,normal,TagsPlugin,blocker,duplicate,cursor,hasienda,0.12
