Author: phd
Date: Fri May 25 12:48:01 2012
New Revision: 4534
Log:
Merged revision 4532 from branch 1.2: use cache.tryGet() instead of cache.get().
Modified:
SQLObject/trunk/sqlobject/main.py
SQLObject/trunk/sqlobject/tests/test_pickle.py
Modified: SQLObject/trunk/sqlobject/main.py
==============================================================================
--- SQLObject/trunk/sqlobject/main.py Fri May 25 12:47:15 2012 (r4533)
+++ SQLObject/trunk/sqlobject/main.py Fri May 25 12:48:01 2012 (r4534)
@@ -1682,15 +1682,14 @@
return d
def __setstate__(self, d):
- id = d['id']
- cls = self.__class__
- cache = self._connection.cache
- if cache.get(id, cls) is not None:
- raise ValueError(
- "Cannot unpickle %s row with id=%s - the id already exists in the cache" % (cls.__name__, id))
self.__init__(_SO_fetch_no_create=1)
self._SO_writeLock = threading.Lock()
self.__dict__.update(d)
+ cls = self.__class__
+ cache = self._connection.cache
+ if cache.tryGet(self.id, cls) is not None:
+ raise ValueError(
+ "Cannot unpickle %s row with id=%s - a different instance with the id already exists in the cache" % (cls.__name__, self.id))
cache.created(id, cls, self)
Modified: SQLObject/trunk/sqlobject/tests/test_pickle.py
==============================================================================
--- SQLObject/trunk/sqlobject/tests/test_pickle.py Fri May 25 12:47:15 2012 (r4533)
+++ SQLObject/trunk/sqlobject/tests/test_pickle.py Fri May 25 12:48:01 2012 (r4534)
@@ -15,15 +15,16 @@
def test_pickleCol():
setupClass(TestPickle)
+ connection = TestPickle._connection
test = TestPickle(question=test_question, answer=test_answer)
pickle_data = pickle.dumps(test, pickle.HIGHEST_PROTOCOL)
+ connection.cache.clear()
test = pickle.loads(pickle_data)
assert test.question == test_question
assert test.answer == test_answer
- connection = TestPickle._connection
if (connection.dbName == 'sqlite') and connection._memory:
return # The following test requires a different connection
|