From b63860249f8a50b04fda73fae1d04d1fbbcc03a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Calonne?= <aurel@nexedi.com> Date: Mon, 2 Aug 2010 11:36:19 +0000 Subject: [PATCH] add a new property on catalog so that developer can decide if he wants to have error raised on UID check or not git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@37397 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ZSQLCatalog/SQLCatalog.py | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/product/ZSQLCatalog/SQLCatalog.py b/product/ZSQLCatalog/SQLCatalog.py index f7fe966559..5ae254830c 100644 --- a/product/ZSQLCatalog/SQLCatalog.py +++ b/product/ZSQLCatalog/SQLCatalog.py @@ -512,6 +512,12 @@ class Catalog(Folder, 'type': 'multiple selection', 'select_variable' : 'getPythonMethodIds', 'mode': 'w' }, + { 'id': 'sql_catalog_raise_error_on_uid_check', + 'title': 'Raise error on UID check', + 'description': 'Boolean used to tell if we raise error when uid check fail', + 'type': 'boolean', + 'default' : True, + 'mode': 'w' }, ) @@ -551,6 +557,7 @@ class Catalog(Folder, sql_catalog_role_keys = () sql_catalog_local_role_keys = () sql_catalog_table_vote_scripts = () + sql_catalog_raise_error_on_uid_check = True # These are ZODB variables, so shared by multiple Zope instances. # This is set to the last logical time when clearReserved is called. @@ -1318,9 +1325,13 @@ class Catalog(Folder, raise RuntimeError, 'could not set missing uid for %r' % (object,) elif check_uid: if uid in assigned_uid_dict: - raise ValueError('uid of %r is %r and ' - 'is already assigned to %s in catalog !!! This can be fatal.' % - (object, uid, assigned_uid_dict[uid])) + error_message = 'uid of %r is %r and ' \ + 'is already assigned to %s in catalog !!! This can be fatal.' % \ + (object, uid, assigned_uid_dict[uid]) + if not self.sql_catalog_raise_error_on_uid_check: + LOG("SQLCatalog.catalogObjectList", ERROR, error_message) + else: + raise ValueError(error_message) path = object.getPath() index = path_uid_dict.get(path) @@ -1370,10 +1381,15 @@ class Catalog(Folder, LOG('SQLCatalog', ERROR, 'uid of %r changed from %r to %r as old one is assigned' ' to %s in catalog !!! This can be fatal.' % ( - 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.' % - (object, uid, catalog_path)) + object, uid, object.uid, catalog_path)) + + error_message = 'uid of %r is %r and ' \ + 'is already assigned to %s in catalog !!! This can be fatal.' \ + % (object, uid, catalog_path) + if not self.sql_catalog_raise_error_on_uid_check: + LOG('SQLCatalog', ERROR, error_message) + else: + raise ValueError(error_message) uid = object.uid assigned_uid_dict[uid] = object -- 2.30.9