[z3-checkins] r41791 - z3/sqlos/trunk/src/sqlos

kobold at codespeak.net kobold at codespeak.net
Mon Apr 2 08:22:56 CEST 2007


Author: kobold
Date: Mon Apr  2 08:22:53 2007
New Revision: 41791

Modified:
   z3/sqlos/trunk/src/sqlos/_transaction.py
Log:
Fixed a bug.


Modified: z3/sqlos/trunk/src/sqlos/_transaction.py
==============================================================================
--- z3/sqlos/trunk/src/sqlos/_transaction.py	(original)
+++ z3/sqlos/trunk/src/sqlos/_transaction.py	Mon Apr  2 08:22:53 2007
@@ -44,9 +44,23 @@
 
     This function should not cause SQL to be sent as it is not defined whether
     the SQL connection will commit before or after this is executed.
+
+    This method should work even if the object doesn't have an id attribute: it
+    sometimes happens that SQLObject instances don't have one.
+
+        >>> class Dummy:
+        ...     def expire(self):
+        ...         print "Expires"
+
+        >>> obj = Dummy()
+        >>> expireSQLObject(obj)
+        Expires
+
     """
-    for connection in connCache.values():
-        connection.cache.expire(obj.id, obj.__class__)
+    # Sometimes, the object doesn't have the id: in this case, ignore it.
+    if hasattr(obj, 'id'):
+        for connection in connCache.values():
+            connection.cache.expire(obj.id, obj.__class__)
 
     # Expire object values. The transaction has either been aborted or
     # committed.


More information about the z3-checkins mailing list