Commit 5340aacb authored by Jérome Perrin's avatar Jérome Perrin

Folder: fix checkConsistency on folder containing non erp5 objects

contentValues() nowadays return also non ERP5-ish objects such as python
scripts , OFS.File etc. Because of that, if an ERP5 Folder contained a
non ERP5 object, which does not have fixConsistency or checkConsistency
methods, Folder.checkConsistency was causing an infinite loop because it
was acquiring checkConsistency method from self.

See merge request !1076
parents fff0b2d4 96031946
Pipeline #8473 passed with stage
...@@ -1616,6 +1616,32 @@ class TestConstraint(PropertySheetTestCase): ...@@ -1616,6 +1616,32 @@ class TestConstraint(PropertySheetTestCase):
document.checkConsistency() document.checkConsistency()
self.assertEqual("Fooa", document.getTitle()) self.assertEqual("Fooa", document.getTitle())
def test_checkConsistency_is_recursive(self):
self._addProperty(
self.object_content_portal_type,
self.id(),
commit=True,
property_id="title_constraint",
portal_type='Attribute Equality Constraint',
constraint_attribute_name = 'title',
constraint_attribute_value = 'string:a',
)
obj = self._makeOne()
self.assertEqual([], obj.checkConsistency())
self.assertEqual([], obj.fixConsistency())
obj.newContent(portal_type=self.object_content_portal_type)
self.assertEqual(1, len(obj.checkConsistency()))
self.assertEqual(1, len(obj.fixConsistency()))
# non ERP5 objects are ignored
from OFS.Image import manage_addFile
manage_addFile(obj, self.id(),)
self.assertEqual(1, len(obj.checkConsistency()))
self.assertEqual(1, len(obj.fixConsistency()))
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestConstraint)) suite.addTest(unittest.makeSuite(TestConstraint))
......
...@@ -1465,11 +1465,11 @@ class Folder(FolderMixIn, CopyContainer, ObjectManager, Base, OFSFolder2, CMFBTr ...@@ -1465,11 +1465,11 @@ class Folder(FolderMixIn, CopyContainer, ObjectManager, Base, OFSFolder2, CMFBTr
# of this name implement consistency checking on object # of this name implement consistency checking on object
continue continue
if fixit: if fixit:
extra_errors = obj.fixConsistency(filter=filter, **kw) if hasattr(aq_base(obj), 'fixConsistency'):
error_list.extend(obj.fixConsistency(filter=filter, **kw))
else: else:
extra_errors = obj.checkConsistency(filter=filter, **kw) if hasattr(aq_base(obj), 'checkConsistency'):
if len(extra_errors) > 0: error_list.extend(obj.checkConsistency(filter=filter, **kw))
error_list += extra_errors
# We should also return an error if any # We should also return an error if any
return error_list return error_list
......
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