Commit 1df47a3a authored by Sebastien Robin's avatar Sebastien Robin

* 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

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@28207 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 6da814fb
...@@ -3819,6 +3819,12 @@ VALUES ...@@ -3819,6 +3819,12 @@ VALUES
self.assertEquals(1, len(res)) self.assertEquals(1, len(res))
def test_CatalogUidDuplicates(self, quiet=quiet, run=run_all_test): 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 run: return
if not quiet: if not quiet:
message = 'Catalog Uid Duplicates' message = 'Catalog Uid Duplicates'
...@@ -3852,15 +3858,7 @@ VALUES ...@@ -3852,15 +3858,7 @@ VALUES
# Force to assign the same uid, and catalog them. # Force to assign the same uid, and catalog them.
person1.uid = person2.uid = available_uid person1.uid = person2.uid = available_uid
person1.is_indexable = person2.is_indexable = True person1.is_indexable = person2.is_indexable = True
portal_catalog.catalogObjectList([person1, person2]) self.assertRaises(ValueError, 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())
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
......
...@@ -1313,10 +1313,10 @@ class Catalog(Folder, ...@@ -1313,10 +1313,10 @@ class Catalog(Folder,
elif check_uid: elif check_uid:
uid = object.uid uid = object.uid
if uid in assigned_uid_dict: if uid in assigned_uid_dict:
object.uid = self.newUid() raise ValueError('uid of %r is %r and \
LOG('SQLCatalog', ERROR, is already assigned to %s in catalog !!! This can be fatal. You \
'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])) should reindex the whole site immediately.' % \
uid = object.uid (object, uid, assigned_uid_dict[uid]))
path = object.getPath() path = object.getPath()
index = path_uid_dict.get(path, None) index = path_uid_dict.get(path, None)
...@@ -1329,9 +1329,9 @@ class Catalog(Folder, ...@@ -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) 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): if uid != index or isinstance(uid, int):
# We want to make sure that uid becomes long if it is an 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)) raise ValueError('uid of %r changed from %r (property) to %r \
uid = index (catalog, by path) !!! This can be fatal. You should reindex \
object.uid = uid the whole site immediately.' % (object, uid, index))
else: else:
# Make sure no duplicates - ie. if an object with different path has same uid, we need a new uid # 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) # This can be very dangerous with relations stored in a category table (CMFCategory)
...@@ -1368,9 +1368,12 @@ class Catalog(Folder, ...@@ -1368,9 +1368,12 @@ class Catalog(Folder,
if len(path) > MAX_PATH_LEN: 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,)) 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, 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)) '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 uid = object.uid
assigned_uid_dict[uid] = object assigned_uid_dict[uid] = object
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment