From 953f572b2008c47594df790cb84c88faae92c0f5 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Mon, 19 May 2008 23:43:33 -0700 Subject: [PATCH] Bug fix: Clear the memcache, search for notes in an main notebook (as the anonymous user), open a search result from a notebook. Then, login and try to edit that notebook as a user with read-write privileges. it will show up as read-only, presumably because it's being read from the cache. --- NEWS | 4 ++++ controller/Database.py | 21 ++++++++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/NEWS b/NEWS index 4321c19..afe2af8 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,7 @@ +1.3.35: May 19, 2008 + * Potential fix for bug where caching of Notebook objects can cause + read-write notebooks to display as read-only. + 1.3.34: May 19, 2008 * Improved performance of searching multiple notebooks. diff --git a/controller/Database.py b/controller/Database.py index be958f1..e83c8a6 100644 --- a/controller/Database.py +++ b/controller/Database.py @@ -6,6 +6,7 @@ import psycopg2 as psycopg from psycopg2.pool import PersistentConnectionPool import random from model.Persistent import Persistent +from model.Notebook import Notebook class Connection_wrapper( object ): @@ -21,6 +22,9 @@ class Database( object ): ID_BITS = 128 # number of bits within an id ID_DIGITS = "0123456789abcdefghijklmnopqrstuvwxyz" + # caching Notebooks causes problems because different users have different read_write/owner values + CLASSES_NOT_TO_CACHE = ( Notebook, ) + def __init__( self, connection = None, cache = None, host = None, ssl_mode = None ): """ Create a new database and return it. @@ -103,7 +107,10 @@ class Database( object ): else: cursor.execute( obj.sql_create() ) - cache = self.__get_cache_connection() + if isinstance( obj, self.CLASSES_NOT_TO_CACHE ): + cache = None + else: + cache = self.__get_cache_connection() if commit: connection.commit() @@ -145,10 +152,10 @@ class Database( object ): @rtype: Object_type or NoneType @return: loaded object, or None if no match """ - if revision is None: - cache = self.__get_cache_connection() - else: + if revision or Object_type in self.CLASSES_NOT_TO_CACHE: cache = None + else: + cache = self.__get_cache_connection() if cache: # don't bother caching old revisions obj = cache.get( Persistent.make_cache_key( Object_type, object_id ) ) @@ -175,10 +182,10 @@ class Database( object ): @rtype: Object_type or NoneType @return: loaded object, or None if no match """ - if use_cache: - cache = self.__get_cache_connection() - else: + if not use_cache or Object_type in self.CLASSES_NOT_TO_CACHE: cache = None + else: + cache = self.__get_cache_connection() if cache: cache_key = sha.new( sql_command ).hexdigest()