Opened 13 years ago
Closed 9 years ago
#9238 closed defect (fixed)
ProgrammingError: Cannot operate on a closed cursor
Reported by: | Owned by: | Richard Liao | |
---|---|---|---|
Priority: | highest | Component: | TracTicketTemplatePlugin |
Severity: | critical | Keywords: | ProgrammingError, closed, cursor |
Cc: | Trac Release: | 0.11 |
Description (last modified by )
I had recently installed the trac template plugin and after installation when i ran trac upgrade command it gave me following error.
ProgrammingError: Cannot operate on a closed cursor Trac Version :- 0.12.2 Python Version :- 2.6.2 Plugin Version :- tractickettemplateplugin-r10731.zip
Kindly provide me guidance
Attachments (0)
Change History (10)
comment:1 Changed 13 years ago by
Description: | modified (diff) |
---|
comment:2 Changed 11 years ago by
I'm attempting to deploy trac via configuration management (salt-stack) and this error is causing me grief. I'm going to spend sometime bug hunting but if anyone has any hints please comment.
comment:3 Changed 11 years ago by
The issue is coming from the line:
cursor.execute("UPDATE system SET value=%s WHERE " "name='tt_version'", (schema_version,))
which is located in the upgrade_environment function.
def upgrade_environment(self, db): cursor = db.cursor() cursor.execute("SELECT value FROM system WHERE name='tt_version'") row = cursor.fetchone() if not row: self.environment_created() current_version = 0 else: current_version = int(row[0]) from tickettemplate import upgrades for version in range(current_version + 1, schema_version + 1): for function in upgrades.map.get(version): print textwrap.fill(inspect.getdoc(function)) function(self.env, db) print 'Done.' cursor.execute("UPDATE system SET value=%s WHERE " "name='tt_version'", (schema_version,)) self.log.info('Upgraded tt tables from version %d to %d', current_version, schema_version)
The issue appears to be that when you get to the cursor.execute below the version for loop. The cursor has been closed. Because you can't control what those functions are doing with the database from this scope, I think that you need to grab a new cursor before executing that execute. My fix was just to add another cursor = db.cursor() directly above the cursor.execute.
for version in range(current_version + 1, schema_version + 1): for function in upgrades.map.get(version): print textwrap.fill(inspect.getdoc(function)) function(self.env, db) print 'Done.' cursor = db.cursor() cursor.execute("UPDATE system SET value=%s WHERE " "name='tt_version'", (schema_version,))
Can you please patch this issue so we can use your plugin? We would rather not maintain a forked version for a simple fix like this. Thanks!
comment:4 Changed 11 years ago by
Applied the patch on r13340. The problem seems only happen on sqlite. The fix just bypass the problem. Any advices for the correct solution?
comment:7 Changed 11 years ago by
Keywords: | ProgrammingError closed cursor added |
---|
comment:8 Changed 11 years ago by
It might be that retrieving a new cursor
in the database upgrade functions somehow expires the cursor
in the outerscope, so once the database upgrade functions return there is no longer a valid cursor
in that scope.
comment:10 Changed 9 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
Issue and fix are most likely the same as in #6765. I can't say that I understand this issue though.