diff --git a/product/ERP5/tests/testPredicate.py b/product/ERP5/tests/testPredicate.py index b7eba35177b2993a95d5f24c26a3cadf8e65e13e..3d8a4ba7a0134806ba08ff567b711e4064c8e0f0 100644 --- a/product/ERP5/tests/testPredicate.py +++ b/product/ERP5/tests/testPredicate.py @@ -599,6 +599,22 @@ class TestPredicates(TestPredicateMixIn): test_tales_expression="python: 'france' in here.getRegion()") self.assertTrue(pred_true.test(doc)) + def testPredicateViewWithOutModification(self): + """ Make sure Predicate_view wihout modification does not change + the object.""" + predicate = self.createPredicate() + # when init Predicate, they are nothing + self.assertTrue(getattr(predicate, '_identity_criterion', None) is None) + self.assertTrue(getattr(predicate, '_range_criterion', None) is None) + # just view it, does not create PersistentMapping + predicate.Predicate_view() + self.assertTrue(getattr(predicate, '_identity_criterion', None) is None) + self.assertTrue(getattr(predicate, '_range_criterion', None) is None) + # add property and view it, creates PersistentMapping + predicate.setCriterionPropertyList(['quantity']) + predicate.Predicate_view() + self.assertFalse(getattr(predicate, '_identity_criterion', None) is None) + self.assertFalse(getattr(predicate, '_range_criterion', None) is None) # TODO : # multi membership category diff --git a/product/ERP5Type/Core/Predicate.py b/product/ERP5Type/Core/Predicate.py index 5c7fb93aa44e0c61c594867a1553d4412d2dc83b..e173bd4cb8c1768c2a734b275ed56613fb12b55a 100644 --- a/product/ERP5Type/Core/Predicate.py +++ b/product/ERP5Type/Core/Predicate.py @@ -381,6 +381,10 @@ class Predicate(XMLObject): XXX - It would be better to return criteria in a Criterion class instance """ + # We do not create PersistentMappings first time we *see* Predicate_view. + # Instead, we create them first time we modify Predicate document. + if not self.getCriterionPropertyList(): + return [] if getattr(aq_base(self), '_identity_criterion', None) is None: self._identity_criterion = PersistentMapping() self._range_criterion = PersistentMapping()