Commit baf42abd authored by Nicolas Dumazet's avatar Nicolas Dumazet

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
parent 78a5f4bd
......@@ -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:
......
......@@ -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):
......
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