[SQL-CVS] r1973 - in SQLObject/trunk/sqlobject: . tests
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
|
From: <sub...@co...> - 2006-10-03 17:28:04
|
Author: phd
Date: 2006-10-03 11:28:02 -0600 (Tue, 03 Oct 2006)
New Revision: 1973
Modified:
SQLObject/trunk/sqlobject/main.py
SQLObject/trunk/sqlobject/tests/test_cache.py
Log:
A patch by Dan Pascu <da...@ag...> to break reference loop
between SQLObject and SQLObjectState using weak references.
Modified: SQLObject/trunk/sqlobject/main.py
===================================================================
--- SQLObject/trunk/sqlobject/main.py 2006-10-03 16:42:24 UTC (rev 1972)
+++ SQLObject/trunk/sqlobject/main.py 2006-10-03 17:28:02 UTC (rev 1973)
@@ -35,6 +35,7 @@
"""
import threading
+import weakref
import sqlbuilder
import dbconnection
import col
@@ -246,7 +247,7 @@
declarative.setup_attributes(cls, new_attrs)
def __init__(self, instance):
- self.instance = instance
+ self.instance = weakref.proxy(instance)
def send(cls, signal, *args, **kw):
events.send(signal, cls.soClass, *args, **kw)
@@ -1590,7 +1591,7 @@
class SQLObjectState(object):
def __init__(self, soObject):
- self.soObject = soObject
+ self.soObject = weakref.proxy(soObject)
self.protocol = 'sql'
Modified: SQLObject/trunk/sqlobject/tests/test_cache.py
===================================================================
--- SQLObject/trunk/sqlobject/tests/test_cache.py 2006-10-03 16:42:24 UTC (rev 1972)
+++ SQLObject/trunk/sqlobject/tests/test_cache.py 2006-10-03 17:28:02 UTC (rev 1973)
@@ -35,16 +35,14 @@
assert not s.sqlmeta.expired
CacheTest.sqlmeta.expireAll()
assert s.sqlmeta.expired
- del s
CacheTest.sqlmeta.expireAll()
- s = CacheTest.get(s_id)
+ s1 = CacheTest.get(s_id)
# We should have a new object:
- assert id(s) != obj_id
- obj_id2 = id(s)
- del s
+ assert id(s1) != obj_id
+ obj_id2 = id(s1)
CacheTest._connection.expireAll()
- s = CacheTest.get(s_id)
- assert id(s) != obj_id and id(s) != obj_id2
+ s2 = CacheTest.get(s_id)
+ assert id(s2) != obj_id and id(s2) != obj_id2
def test_cache_cull():
setupClass(CacheTest)
|