#6765 closed defect (fixed)
Hackergotchi doesn't work with trac 0.11.6
Reported by: | Jens Langner | Owned by: | Ryan J Ollos |
---|---|---|---|
Priority: | normal | Component: | HackergotchiPlugin |
Severity: | critical | Keywords: | database, cursor, scope, ProgrammingError, closed |
Cc: | Steffen Hoffmann | Trac Release: | 0.11 |
Description
After trying to install the HackergotchiPlugin in a trac 0.11.6 installation I get the following error:
ProgrammingError: Cannot operate on a closed cursor.
After some investigation and help from #trac I found the following code in Hackergotchi to be responsible for the error. Here is a patch for it:
Index: hackergotchi/web_ui.py =================================================================== --- hackergotchi/web_ui.py (revision 7751) +++ hackergotchi/web_ui.py (working copy) @@ -29,8 +29,6 @@ def filter_stream(self, req, method, filename, stream, data): if req.path_info.startswith('/timeline'): closure_state = [0] - db = self.env.get_db_cnx() - cursor = db.cursor() cache = {} def f(stream): # Update the closed value @@ -43,6 +41,8 @@ if user_info is not None: author, name, email = user_info else: + db = self.env.get_db_cnx() + cursor = db.cursor() user_info = self._get_info(author, cursor) cache[author] = user_info author, name, email = user_info
After applying that patch the error disappeared.
Attachments (0)
Change History (8)
comment:1 Changed 15 years ago by
comment:3 Changed 14 years ago by
Cc: | Steffen Hoffmann added; anonymous removed |
---|
I've been trying to understand this issue by studying various cases where it appears (and it appears quite frequently!). Is it possible that the db object could still be garbage collected with this patch? What about the following alternative patch?
-
0.11/hackergotchi/web_ui.py
29 29 def filter_stream(self, req, method, filename, stream, data): 30 30 if req.path_info.startswith('/timeline'): 31 31 closure_state = [0] 32 db = self.env.get_db_cnx()33 cursor = db.cursor()34 32 cache = {} 35 33 def f(stream): 36 34 # Update the closed value … … 43 41 if user_info is not None: 44 42 author, name, email = user_info 45 43 else: 46 user_info = self._get_info(author, cursor) 44 db = self.env.get_db_cnx() 45 user_info = self._get_info(author, db) 47 46 cache[author] = user_info 48 47 author, name, email = user_info 49 48 … … 75 74 return [] 76 75 77 76 # Internal methods 78 def _get_info(self, author, cursor): 77 def _get_info(self, author, db): 78 cursor = db.cursor() 79 79 if author == 'anonymous': 80 80 # Don't even bother trying for "anonymous" 81 81 return author, None, None
comment:5 Changed 13 years ago by
Owner: | changed from Noah Kantrowitz to Ryan J Ollos |
---|---|
Status: | new → assigned |
comment:6 follow-up: 7 Changed 13 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
(In [11248]) Fixes #6765: Attempt to fix "Cannot operate on a closed cursor." error by passing the db object rather than the cursor object to the subfunction. The assumption here is that the db object is going out of scope.
I wasn't able to reproduce the issue with Trac 0.11 in a development environment. Please report back if this fixes the issue for you.
comment:7 Changed 13 years ago by
Keywords: | database cursor scope added |
---|
Replying to rjollos:
(In [11248]) Fixes #6765: Attempt to fix "Cannot operate on a closed cursor." error by passing the db object rather than the cursor object to the subfunction. The assumption here is that the db object is going out of scope.
Sure, very reasonable IMHO. I've been looking for this kind of issue too after I got bitten by such a similar issue. Cursors should never be passed to methods/functions - another thing for our upcoming best-practice documentation.
comment:8 Changed 11 years ago by
Keywords: | ProgrammingError closed added |
---|
Also see trac:ticket:9077#comment:9