From 42f269b6aeca6f7c19ecc3b765d67bf058c8f4c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com> Date: Tue, 21 Mar 2006 08:41:11 +0000 Subject: [PATCH] cast to correct type before setting the property git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@6154 20353a03-c40f-0410-a6d1-a30d3c3de9de --- .../ERP5Type/Constraint/PropertyTypeValidity.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/product/ERP5Type/Constraint/PropertyTypeValidity.py b/product/ERP5Type/Constraint/PropertyTypeValidity.py index a9a1df0ba7..87cbc98beb 100755 --- a/product/ERP5Type/Constraint/PropertyTypeValidity.py +++ b/product/ERP5Type/Constraint/PropertyTypeValidity.py @@ -64,8 +64,6 @@ class PropertyTypeValidity(Constraint): # Remove _properties error_message = "Instance has local _properties property" if fixit: - # XXX FIXME we have to set exception name ! -# try: local_properties = object._properties del object._properties object._local_properties = [] @@ -74,8 +72,6 @@ class PropertyTypeValidity(Constraint): if p['id'] not in class_property_ids: object._local_properties.append(p) error_message += " (Fixed)" -# except: -# error_message += " (ERROR)" errors.append(self._generateError(object, error_message)) return errors @@ -108,11 +104,13 @@ class PropertyTypeValidity(Constraint): "Attribute %s should be of type %s but is of type %s" % \ (property_id, property_type, str(type(value))) if fixit: - # XXX FIXME do not use except without exception name ! -# try: + # try to cast to correct type + if wrong_type : + try : + value = self._type_dict[property_type][0](value) + except (KeyError, ValueError), error: + error_message += " (Type cast failed : %s)" % error object.setProperty(property_id, value) error_message += " (Fixed)" -# except: -# error_message += " (ERROR)" errors.append(self._generateError(object, error_message)) return errors -- 2.30.9