Index: /WAeUP_SRP/trunk/PatchZCatalogCatalogUpdateMetadata.py
===================================================================
--- /WAeUP_SRP/trunk/PatchZCatalogCatalogUpdateMetadata.py	(revision 2039)
+++ /WAeUP_SRP/trunk/PatchZCatalogCatalogUpdateMetadata.py	(revision 2039)
@@ -0,0 +1,42 @@
+from BTrees.IOBTree import IOBTree
+from random import randint
+def updateMetadata(self, object, uid):
+    """ Given an object and a uid, update the column data for the
+    uid with the object data iff the object has changed """
+    data = self.data
+    index = self.uids.get(uid, None)
+    newDataRecord = self.recordify(object)
+
+    if index is None:
+        if type(data) is IOBTree:
+            # New style, get random id
+
+            index=getattr(self, '_v_nextid', 0)
+            if index % 4000 == 0: 
+                index = randint(-2000000000, 2000000000)
+            while not data.insert(index, newDataRecord):
+                index = randint(-2000000000, 2000000000)
+
+            # We want ids to be somewhat random, but there are
+            # advantages for having some ids generated
+            # sequentially when many catalog updates are done at
+            # once, such as when reindexing or bulk indexing.
+            # We allocate ids sequentially using a volatile base,
+            # so different threads get different bases. This
+            # further reduces conflict and reduces churn in
+            # here and it result sets when bulk indexing.
+            self._v_nextid=index+1
+        else:
+            if data:
+                # find the next available unique id
+                index = data.keys()[-1] + 1
+            else:
+                index=0
+            # meta_data is stored as a tuple for efficiency
+            data[index] = newDataRecord
+    else:
+        #if True or data.get(index, 0) != newDataRecord:
+        data[index] = newDataRecord
+    return index
+from Products.ZCatalog.Catalog import Catalog
+Catalog.udateMetadata = updateMetadata
Index: /WAeUP_SRP/trunk/WAeUPTables.py
===================================================================
--- /WAeUP_SRP/trunk/WAeUPTables.py	(revision 2038)
+++ /WAeUP_SRP/trunk/WAeUPTables.py	(revision 2039)
@@ -550,5 +550,4 @@
             if event_type not in ("sys_add_object","sys_del_object"):
                 return
-            #import pdb;pdb.set_trace()
             level_session = getattr(object.aq_parent.getContent(),'session','unknown')
             if level_session not in (self.getSessionId()[-2:],'2006/2007'):
@@ -562,9 +561,8 @@
                 return
             student_rec = res[0]
-            registered_courses = getattr(student_rec,'registered_courses',[])
-            try:
-                x = course_id in registered_courses
-            except TypeError:
+            registered_courses = getattr(student_rec,'registered_courses',None)
+            if not registered_courses:
                 registered_courses = []
+            #import pdb;pdb.set_trace()
             if event_type == "sys_add_object":
                 if course_id not in registered_courses:
@@ -572,7 +570,11 @@
                 else:
                     return
-            elif event_type == "sys_del_object":
+            elif registered_courses and event_type == "sys_del_object":
+                removed = False
                 while course_id in registered_courses:
+                    removed = True
                     registered_courses.remove(course_id)
+                if not removed:
+                    return
             data['id'] = student_id
             data['registered_courses'] = registered_courses
Index: /WAeUP_SRP/trunk/__init__.py
===================================================================
--- /WAeUP_SRP/trunk/__init__.py	(revision 2038)
+++ /WAeUP_SRP/trunk/__init__.py	(revision 2039)
@@ -24,4 +24,5 @@
 import PatchFasterSessionData
 import PatchQueueCatalogProcessQueue
+import PatchZCatalogCatalogUpdateMetadata
 # Only for CPS 3.4.1. In 3.4.2 and later this should be fixed.
 import PatchCPSDefaultImportExport
