Opened 8 years ago

Closed 7 years ago

Last modified 4 years ago

#6341 closed defect (fixed)

Cannot operate on a closed cursor error

Reported by: lkraav Owned by: lkraav
Priority: normal Component: TracPastePlugin
Severity: normal Keywords: ProgrammingError, closed, cursor
Cc: Michael Renzmann Trac Release: 0.11

Description (last modified by Ryan J Ollos)

2009-12-16 14:26:35,474 Trac[chrome] DEBUG: Prepare chrome data for request
2009-12-16 14:26:35,478 Trac[model] DEBUG: get_pastes() SQL: 'SELECT id, title, author, time FROM pastes ORDER BY id DESC LIMIT 10' (None)
2009-12-16 14:26:35,599 Trac[main] ERROR: Internal Server Error:
Traceback (most recent call last):
  File "/secure/trac/virtual-0.11/trac-src/trac/web/", line 450, in _dispatch_request
  File "/secure/trac/virtual-0.11/trac-src/trac/web/", line 206, in dispatch
    resp = chosen_handler.process_request(req)
  File "build/bdist.linux-i686/egg/tracpaste/", line 141, in process_request
    'recent':           get_pastes(env=self.env, number=self.max_recent)
  File "build/bdist.linux-i686/egg/tracpaste/", line 53, in get_pastes
    cursor.execute(sql, where_values)
  File "/secure/trac/virtual-0.11/trac-src/trac/db/", line 65, in execute
    return self.cursor.execute(sql)
  File "/secure/trac/virtual-0.11/trac-src/trac/db/", line 80, in execute
    PyFormatCursor.execute(self, *args)
  File "/secure/trac/virtual-0.11/trac-src/trac/db/", line 59, in execute
    args or [])
  File "/secure/trac/virtual-0.11/trac-src/trac/db/", line 51, in _rollback_on_error
    return function(self, *args, **kwargs)
ProgrammingError: Cannot operate on a closed cursor.

Attachments (0)

Change History (9)

comment:1 Changed 8 years ago by lkraav

this could be related to #6302.

comment:2 Changed 8 years ago by Ryan J Ollos

Description: modified (diff)
Summary: TracPastePlugin: 0.11.6 - Cannot operate on a closed cursor errorCannot operate on a closed cursor error

#7138 was closed as a duplicate.

comment:3 Changed 7 years ago by Ryan J Ollos

Cc: Michael Renzmann added; anonymous removed

Isn't this (source:tracpasteplugin/0.11/tracpaste/

cursor = (db or env.get_db_cnx()).cursor()

just as bad of a practice as?:

cursor = env.get_db_cnx().cursor

Shouldn't we replace that code with?:

db = (db or env.get_db_cnx())
cursor = db.cursor()

Per t:wiki:TracDev/DatabaseApi#APIbeforeTrac0.12

comment:4 Changed 7 years ago by Ryan J Ollos

Since I have TracPastePlugin setup in a dev environment following #8298, I'd be happy to apply the proposed fix for this as well, given permission of the maintainer.

  • 0.11/tracpaste/

    2929    To get the paste data, use id to instantiate a Paste object."""
    31     cursor = (db or env.get_db_cnx()).cursor()
     31    db = db or env.get_db_cnx()
     32    cursor = db.cursor()
    3334    sql = "SELECT id, title, author, time FROM pastes"
    3435    order_clause = " ORDER BY id DESC"

comment:5 Changed 7 years ago by Ryan J Ollos

#6361 closed as a duplicate.

comment:6 Changed 7 years ago by osimons

Patch looks good to me.

comment:7 Changed 7 years ago by Michael Renzmann

No objections from me. Feel free to commit.

comment:8 Changed 7 years ago by Ryan J Ollos

Resolution: fixed
Status: newclosed

(In [9678]) Attempt to resolve reported closed cursor error by making sure db object does not get removed up by Python. Version bumped to 0.2.2. Fixes #6341.

comment:9 Changed 4 years ago by Ryan J Ollos

Keywords: ProgrammingError closed cursor added

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain lkraav.
The resolution will be deleted.

Add Comment

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

Note: See TracTickets for help on using tickets.