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
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()
......
......@@ -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
......
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