Modify

Opened 13 years ago

Closed 10 years ago

#9238 closed defect (fixed)

ProgrammingError: Cannot operate on a closed cursor

Reported by: viveikcpuglia@… Owned by: Richard Liao
Priority: highest Component: TracTicketTemplatePlugin
Severity: critical Keywords: ProgrammingError, closed, cursor
Cc: Trac Release: 0.11

Description (last modified by Ryan J Ollos)

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 Ryan J Ollos

Description: modified (diff)

Issue and fix are most likely the same as in #6765. I can't say that I understand this issue though.

comment:2 Changed 11 years ago by anonymous

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 Travis F.

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 Richard Liao

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:5 Changed 11 years ago by Ryan J Ollos

I'm not sure what the issue is, but #6902 looks similar.

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

comment:6 Changed 11 years ago by Ryan J Ollos

In 13633:

0.8: Bump version to 0.8. Added SVN revision to egg. Refs #6589, #6809, #7311, #7404, #7440, #8555, #8609, #9238, #10858.

comment:7 Changed 11 years ago by Ryan J Ollos

Keywords: ProgrammingError closed cursor added

comment:8 Changed 11 years ago by Ryan J Ollos

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:9 Changed 10 years ago by Ryan J Ollos

This issue won't be seen on the new 1.0 branch.

comment:10 Changed 10 years ago by Ryan J Ollos

Resolution: fixed
Status: newclosed

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Richard Liao.
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.