Modify

Opened 3 years ago

Last modified 6 months ago

#9238 new defect

ProgrammingError: Cannot operate on a closed cursor

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

Description (last modified by rjollos)

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 (8)

comment:1 Changed 3 years ago by rjollos

  • 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 13 months 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 13 months 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 13 months ago by richard

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 13 months ago by rjollos

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

Last edited 13 months ago by rjollos (previous) (diff)

comment:6 Changed 7 months ago by rjollos

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 6 months ago by rjollos

  • Keywords ProgrammingError closed cursor added

comment:8 Changed 6 months ago by rjollos

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.

Add Comment

Modify Ticket

Action
as new .
Author


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

 
Note: See TracTickets for help on using tickets.