From baf42abde7c137200f2a1638d98662ec2d42b069 Mon Sep 17 00:00:00 2001 From: Nicolas Dumazet <nicolas.dumazet@nexedi.com> Date: Wed, 9 Feb 2011 03:47:19 +0000 Subject: [PATCH] Add a testcase and fix the usage when one adds an empty, or invalid, or incorrect property to a propertysheet. It was okay, with filesystem property sheets to raise an error: worst case scenario, the developer would have to fix the property sheet and restart the instance. But with ZODB property sheets, raising an error can potentially break the instance. We replace the error by a LOG: you're likely to see this when editing properties. This is not a "dirty quickfix", this is not a workaround to go faster: this behavior will stay. If you feel that it's a wrong way to do, do tell us. git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@43199 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ERP5Type/Utils.py | 10 ++++--- .../tests/testDynamicClassGeneration.py | 26 +++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/product/ERP5Type/Utils.py b/product/ERP5Type/Utils.py index 449b9f3a6a..aaa8010001 100644 --- a/product/ERP5Type/Utils.py +++ b/product/ERP5Type/Utils.py @@ -1499,6 +1499,12 @@ def setDefaultProperties(property_holder, object=None, portal=None): converted_prop_list = [] converted_prop_set = set() for prop in prop_list: + if prop['type'] not in type_definition: + LOG("ERP5Type.Utils", INFO, + "Invalid type '%s' of property '%s' for Property Sheet '%s'" % \ + (prop['type'], prop['id'], property_holder.__name__)) + continue + read_permission = prop.get('read_permission', Permissions.AccessContentsInformation) if isinstance(read_permission, Expression): @@ -1507,9 +1513,7 @@ def setDefaultProperties(property_holder, object=None, portal=None): Permissions.ModifyPortalContent) if isinstance(write_permission, Expression): write_permission = write_permission(econtext) - if prop['type'] not in type_definition: - raise TypeError, '"%s" is invalid type for propertysheet' % \ - prop['type'] + if 'base_id' in prop: continue if prop['id'] not in converted_prop_set: diff --git a/product/ERP5Type/tests/testDynamicClassGeneration.py b/product/ERP5Type/tests/testDynamicClassGeneration.py index 4b6f26f67f..e2d27d0cb7 100644 --- a/product/ERP5Type/tests/testDynamicClassGeneration.py +++ b/product/ERP5Type/tests/testDynamicClassGeneration.py @@ -999,6 +999,32 @@ class TestZodbPropertySheet(ERP5TypeTestCase): self.test_module.setTitle, 'my_property_type_validity_constraint_title') + def testAddEmptyProperty(self): + """ + When users create properties in a PropertySheet, the property + is first empty. + Check that accessor generation can cope with such invalid + properties + """ + property_sheet_tool = self.portal.portal_property_sheets + arrow = property_sheet_tool.Arrow + + # Action -> add Acquired Property + arrow.newContent(portal_type="Acquired Property") + # a user is doing this, so commit after each request + transaction.commit() + + accessor = getattr(property_sheet_tool, "setTitle", None) + # sites used to break at this point + self.assertNotEquals(None, accessor) + # try to create a Career, which uses Arrow Property Sheet + person_module = self.portal.person_module + person = person_module.newContent(portal_type="Person") + try: + person.newContent(portal_type="Career") + except TypeError: + self.fail("Arrow Property Sheet could not be generated") + from Products.CMFCore.Expression import Expression class TestZodbImportFilesystemPropertySheet(ERP5TypeTestCase): -- 2.30.9