diff --git a/product/ERP5Catalog/tests/testERP5Catalog.py b/product/ERP5Catalog/tests/testERP5Catalog.py index c58130d68e37755e4a617b7f22c159632a98bc71..b60dbadec89f2c4086c2c8c61c5095cdc8da3bb2 100644 --- a/product/ERP5Catalog/tests/testERP5Catalog.py +++ b/product/ERP5Catalog/tests/testERP5Catalog.py @@ -3819,6 +3819,12 @@ VALUES 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 @@ VALUES # 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() diff --git a/product/ZSQLCatalog/SQLCatalog.py b/product/ZSQLCatalog/SQLCatalog.py index 81a00cb8006531f98fa2d9f3c82409e9e9670190..b4b2069b9b0754e0fb7841fad8f09c71e43d6dcc 100644 --- a/product/ZSQLCatalog/SQLCatalog.py +++ b/product/ZSQLCatalog/SQLCatalog.py @@ -1313,10 +1313,10 @@ class Catalog(Folder, 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 @@ class Catalog(Folder, 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 @@ class Catalog(Folder, 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