[Erp5-report] r28207 - in /erp5/trunk/products: ERP5Catalog/tests/ ZSQLCatalog/

nobody at svn.erp5.org nobody at svn.erp5.org
Wed Jul 29 14:50:32 CEST 2009


Author: seb
Date: Wed Jul 29 14:50:31 2009
New Revision: 28207

URL: http://svn.erp5.org?rev=28207&view=rev
Log:
* change unit test of catalog in order to check that wrong uid in catalog
  is raising errors
* make the catalog raising errors
* Change messages about uid duplication

Modified:
    erp5/trunk/products/ERP5Catalog/tests/testERP5Catalog.py
    erp5/trunk/products/ZSQLCatalog/SQLCatalog.py

Modified: erp5/trunk/products/ERP5Catalog/tests/testERP5Catalog.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Catalog/tests/testERP5Catalog.py?rev=28207&r1=28206&r2=28207&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Catalog/tests/testERP5Catalog.py [utf8] (original)
+++ erp5/trunk/products/ERP5Catalog/tests/testERP5Catalog.py [utf8] Wed Jul 29 14:50:31 2009
@@ -3819,6 +3819,12 @@
     self.assertEquals(1, len(res))
 
   def test_CatalogUidDuplicates(self, quiet=quiet, run=run_all_test):
+    """
+    Initially, the catalog was changing uids when a duplicate was found.
+
+    This operation was really too dangerous, so now we raise errors in this
+    case. Here we now check that the error is raised
+    """
     if not run: return
     if not quiet:
       message = 'Catalog Uid Duplicates'
@@ -3852,15 +3858,7 @@
     # Force to assign the same uid, and catalog them.
     person1.uid = person2.uid = available_uid
     person1.is_indexable = person2.is_indexable = True
-    portal_catalog.catalogObjectList([person1, person2])
-
-    # The catalog must have either or both of their uids, so 
-    # the objects must have different ones at this point.
-    self.assertNotEquals(person1.uid, person2.uid)
-    
-    # And they must have been catalogued.
-    self.assertEquals(person1, portal_catalog(uid=person1.uid)[0].getObject())
-    self.assertEquals(person2, portal_catalog(uid=person2.uid)[0].getObject())
+    self.assertRaises(ValueError, portal_catalog.catalogObjectList,[person1, person2])
 
 def test_suite():
   suite = unittest.TestSuite()

Modified: erp5/trunk/products/ZSQLCatalog/SQLCatalog.py
URL: http://svn.erp5.org/erp5/trunk/products/ZSQLCatalog/SQLCatalog.py?rev=28207&r1=28206&r2=28207&view=diff
==============================================================================
--- erp5/trunk/products/ZSQLCatalog/SQLCatalog.py [utf8] (original)
+++ erp5/trunk/products/ZSQLCatalog/SQLCatalog.py [utf8] Wed Jul 29 14:50:31 2009
@@ -1313,10 +1313,10 @@
       elif check_uid:
         uid = object.uid
         if uid in assigned_uid_dict:
-          object.uid = self.newUid()
-          LOG('SQLCatalog', ERROR,
-              'uid of %r changed from %r to %r as old one is assigned to %r !!! This can be fatal. You should reindex the whole site immediately.' % (object, uid, object.uid, assigned_uid_dict[uid]))
-          uid = object.uid
+          raise ValueError('uid of %r is %r and \
+              is already assigned to %s in catalog !!! This can be fatal. You \
+              should reindex the whole site immediately.' % \
+              (object, uid, assigned_uid_dict[uid]))
 
         path = object.getPath()
         index = path_uid_dict.get(path, None)
@@ -1329,9 +1329,9 @@
             raise CatalogError, 'A negative uid %d is used for %s. Your catalog is broken. Recreate your catalog.' % (index, path)
           if uid != index or isinstance(uid, int):
             # We want to make sure that uid becomes long if it is an int
-            LOG('SQLCatalog', ERROR, 'uid of %r changed from %r (property) to %r (catalog, by path) !!! This can be fatal. You should reindex the whole site immediately.' % (object, uid, index))
-            uid = index
-            object.uid = uid
+            raise ValueError('uid of %r changed from %r (property) to %r \
+                (catalog, by path) !!! This can be fatal. You should reindex \
+                the whole site immediately.' % (object, uid, index))
         else:
           # Make sure no duplicates - ie. if an object with different path has same uid, we need a new uid
           # This can be very dangerous with relations stored in a category table (CMFCategory)
@@ -1368,9 +1368,12 @@
             if len(path) > MAX_PATH_LEN:
               LOG('SQLCatalog', ERROR, 'path of object %r is too long for catalog. You should use a shorter path.' %(object,))
 
-            object.uid = self.newUid()
             LOG('SQLCatalog', ERROR,
                 'uid of %r changed from %r to %r as old one is assigned to %s in catalog !!! This can be fatal. You should reindex the whole site immediately.' % (object, uid, object.uid, catalog_path))
+            raise ValueError('uid of %r is %r  and \
+                is already assigned to %s in catalog !!! This can be fatal. You \
+                should reindex the whole site immediately.' % \
+                (object, uid, catalog_path))
             uid = object.uid
 
         assigned_uid_dict[uid] = object




More information about the Erp5-report mailing list