Commit 483c66e4 authored by Ayush Tiwari's avatar Ayush Tiwari Committed by Ayush Tiwari

bt5_config: Do not convert to XML to compare objects

parent 41fa3aac
......@@ -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):
......
......@@ -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
......
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