Modify

Opened 11 years ago

Closed 11 years ago

Last modified 10 years ago

#11115 closed defect (fixed)

Cannot operate on closed cursor

Reported by: Ryan J Ollos Owned by: Ryan J Ollos
Priority: normal Component: BookmarkPlugin
Severity: normal Keywords: ProgrammingError, closed, cursor
Cc: Jun Omae, Ryan J Ollos Trac Release:

Description

While testing with Trac 0.11, I've seen the following in the logs:

11:17:19 AM Trac[main] ERROR: Cannot operate on a closed cursor.
Traceback (most recent call last):
  File "/home/user/Workspace/th11043/trac-0.11/trac/web/main.py", line 233, in dispatch
    self._post_process_request(req)
  File "/home/user/Workspace/th11043/trac-0.11/trac/web/main.py", line 301, in _post_process_request
    f.post_process_request(req, *(None,)*extra_arg_count)
  File "/home/user/Workspace/trachacks.git/bookmarkplugin/trunk/tracbookmark/__init__.py", line 183, in post_process_request
    self.render_bookmarker(req)
  File "/home/user/Workspace/trachacks.git/bookmarkplugin/trunk/tracbookmark/__init__.py", line 335, in render_bookmarker
    menu = self._get_bookmarks_menu(req)
  File "/home/user/Workspace/trachacks.git/bookmarkplugin/trunk/tracbookmark/__init__.py", line 342, in _get_bookmarks_menu
    for url, name, username in self.get_bookmarks(req):
  File "/home/user/Workspace/th11043/trac-0.11/trac/db/util.py", line 40, in __iter__
    row = self.cursor.fetchone()
ProgrammingError: Cannot operate on a closed cursor.

The error occurs when loading any page, such as WikiStart. I think we shouldn't be returning a cursor from get_bookmarks.

Attachments (0)

Change History (4)

comment:1 Changed 11 years ago by Jun Omae

Indeed. We must keep the db variable while in use of cursor. See https://groups.google.com/forum/?fromgroups#!msg/trac-dev/trRtzv5waoQ/Uz1T1sBhTR8J and http://trac.edgewall.org/changeset/8878.

  • tracbookmark/__init__.py

     
    6161        cursor.execute(
    6262            "SELECT resource, name, username FROM bookmarks WHERE username=%s",
    6363            (get_reporter_id(req),))
    64         return cursor
     64        for row in cursor:
     65            yield row
    6566
    6667    def get_bookmark(self, req, resource):
    6768        """Return the current users bookmark for a resource."""

comment:2 Changed 11 years ago by Ryan J Ollos

Owner: changed from yosiyuki to Ryan J Ollos
Status: newassigned

Thanks! Initially I had just called fetchall on the cursor, but returning an iterator is probably better.

comment:3 Changed 11 years ago by Ryan J Ollos

Resolution: fixed
Status: assignedclosed

(In [13227]) Fixes #11115: Avoid Cannot operate on closed cursor errors by not returning a cursor from a function.

comment:4 Changed 10 years ago by Ryan J Ollos

Cc: Ryan J Ollos added
Keywords: ProgrammingError closed cursor added

Modify Ticket

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