[Checkins] SVN: z3c.relationfield/trunk/ Fix a bug that occurred when IObjectModified event was fired before

Martijn Faassen faassen at infrae.com
Thu Feb 12 11:18:27 EST 2009


Log message for revision 96472:
  Fix a bug that occurred when IObjectModified event was fired before
  the object is added somewhere; assume IObjectAdded event is fired
  before IObjectModified event needs to be handled.
  

Changed:
  U   z3c.relationfield/trunk/CHANGES.txt
  U   z3c.relationfield/trunk/src/z3c/relationfield/event.py

-=-
Modified: z3c.relationfield/trunk/CHANGES.txt
===================================================================
--- z3c.relationfield/trunk/CHANGES.txt	2009-02-12 13:45:00 UTC (rev 96471)
+++ z3c.relationfield/trunk/CHANGES.txt	2009-02-12 16:18:27 UTC (rev 96472)
@@ -1,10 +1,12 @@
 CHANGES
 *******
 
-0.5 (unreleased)
-================
+0.4.1 (unreleased)
+==================
 
-* ...
+* Don't handle ``IObjectModified`` events for objects that do not yet
+  have a parent. There is no need to do so anyway, as these objects cannot
+  have outgoing relations indexed.
 
 0.4 (2009-02-10)
 ================

Modified: z3c.relationfield/trunk/src/z3c/relationfield/event.py
===================================================================
--- z3c.relationfield/trunk/src/z3c/relationfield/event.py	2009-02-12 13:45:00 UTC (rev 96471)
+++ z3c.relationfield/trunk/src/z3c/relationfield/event.py	2009-02-12 16:18:27 UTC (rev 96472)
@@ -43,10 +43,15 @@
 def updateRelations(obj, event):
     """Re-register relations, after they have been changed.
     """
+    # if we do not yet have a parent, we ignore this modified event
+    # completely. The object will need to be added somewhere first
+    # before modification events will have an effect
+    if obj.__parent__ is None:
+        return
+
+    # remove previous relations coming from id (now have been overwritten)
     catalog = component.getUtility(ICatalog)
     intids = component.getUtility(IIntIds)
-
-    # remove previous relations coming from id (now have been overwritten)
     # have to activate query here with list() before unindexing them so we don't
     # get errors involving buckets changing size
     rels = list(catalog.findRelations({'from_id': intids.getId(obj)}))



More information about the Checkins mailing list