diff --git a/product/ERP5/Document/BusinessManager.py b/product/ERP5/Document/BusinessManager.py index 2c3a84e7df23e88f91a133c51f62afaf2f036582..41eeee80c4f7dcaff736db2afda266fc4e0cdae0 100644 --- a/product/ERP5/Document/BusinessManager.py +++ b/product/ERP5/Document/BusinessManager.py @@ -38,6 +38,7 @@ import hashlib import fnmatch import re import threading +import pprint from copy import deepcopy from collections import defaultdict from cStringIO import StringIO @@ -615,7 +616,9 @@ class BusinessItem(Implicit, Persistent): try: sha256 = hashlib.sha256(self._value).hexdigest() except TypeError: - sha256 = hashlib.sha256(self._value.asXML()).hexdigest() + obj_dict = self._value.__dict__.copy() + del obj_dict['uid'] + sha256 = hash(pprint.pformat(obj_dict)) self._sha = sha256 def build(self, context, **kw): diff --git a/product/ERP5/Tool/TemplateTool.py b/product/ERP5/Tool/TemplateTool.py index 9662126e420aa673c47ca069ea240deafda17ea2..fa0be5c1dad1746bb057b043e171b764ae63c912 100644 --- a/product/ERP5/Tool/TemplateTool.py +++ b/product/ERP5/Tool/TemplateTool.py @@ -34,6 +34,7 @@ import os import shutil import sys import hashlib +import pprint from Acquisition import Implicit, Explicit from AccessControl import ClassSecurityInfo @@ -1779,7 +1780,20 @@ class TemplateTool (BaseTool): try: obj = portal.restrictedTraverse(path) - obj_sha = hashlib.sha256(obj.asXML()).hexdigest() + # Use shallow copy of the dict of the object at ZODB after removing + # attributes which changes at small updation, like workflow_history, + # uid, volatile attributes(which starts with _v) + obj_dict = obj.__dict__.copy() + removable_attributes = [attr for attr + in obj_dict.keys() + if attr.startswith('_v')] + + removable_attributes.append('uid') + for attr in removable_attributes: + del obj_dict[attr] + + obj_sha = hash(pprint.pformat(obj_dict)) + # Get item at old state old_item = old_state.getBusinessItemByPath(path) # Check if there is an object at old state at this path @@ -1826,7 +1840,7 @@ class TemplateTool (BaseTool): # Raise error error_list.append('Trying to remove changes at ZODB at %s' % path) - except Exception: + except KeyError: # Get item at old state old_item = old_state.getBusinessItemByPath(path) # Check if there is an object at old state at this path