From 9db59e7d7553000533e28740676ede338debcf25 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Mon, 25 Apr 2022 03:05:14 +0200
Subject: [PATCH] PropertyRecordableMixin: clear _recorded_property_dict if
 empty

This makes smaller pickles
---
 .../portal_components/test.erp5.testPropertyRecordable.py       | 2 ++
 product/ERP5/mixin/property_recordable.py                       | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/bt5/erp5_core_test/TestTemplateItem/portal_components/test.erp5.testPropertyRecordable.py b/bt5/erp5_core_test/TestTemplateItem/portal_components/test.erp5.testPropertyRecordable.py
index 5bdbb95b25..0f130bfd45 100644
--- a/bt5/erp5_core_test/TestTemplateItem/portal_components/test.erp5.testPropertyRecordable.py
+++ b/bt5/erp5_core_test/TestTemplateItem/portal_components/test.erp5.testPropertyRecordable.py
@@ -82,6 +82,7 @@ class TestPropertyRecordable(ERP5TypeTestCase):
     p.clearRecordedProperty('first_name')
     self.assertFalse(p.isPropertyRecorded('first_name'))
     self.assertTrue(p.isPropertyRecorded('last_name'))
+    self.assertTrue(hasattr(p, '_recorded_property_dict'))
 
     # clearing a property that is not currently recorded is not an error
     p.clearRecordedProperty('description')
@@ -89,5 +90,6 @@ class TestPropertyRecordable(ERP5TypeTestCase):
     p.clearRecordedProperty('last_name')
     self.assertFalse(p.isPropertyRecorded('first_name'))
     self.assertFalse(p.isPropertyRecorded('last_name'))
+    self.assertFalse(hasattr(p, '_recorded_property_dict'))
 
     p.clearRecordedProperty('description')
diff --git a/product/ERP5/mixin/property_recordable.py b/product/ERP5/mixin/property_recordable.py
index 5cfae5e809..14b67f9e32 100644
--- a/product/ERP5/mixin/property_recordable.py
+++ b/product/ERP5/mixin/property_recordable.py
@@ -87,6 +87,8 @@ class PropertyRecordableMixin:
     the property record.
     """
     self._getRecordedPropertyDict({}).pop(id, None)
+    if not self._getRecordedPropertyDict(True):
+      del self._recorded_property_dict
 
   security.declareProtected(Permissions.AccessContentsInformation,
                             'getRecordedPropertyIdList')
-- 
2.30.9