Commit 242fac2e authored by Ayush Tiwari's avatar Ayush Tiwari

bt5_config: Calculate hash before comparing installation states and ZODB

parent 6dc7d1d6
...@@ -752,7 +752,6 @@ class BusinessItem(Implicit, Persistent): ...@@ -752,7 +752,6 @@ class BusinessItem(Implicit, Persistent):
if self._sign == 1: if self._sign == 1:
# install object # install object
obj = self._value obj = self._value
obj = obj._getCopy(container)
container._setObject(object_id, obj) container._setObject(object_id, obj)
obj = container._getOb(object_id) obj = container._getOb(object_id)
obj.isIndexable = ConstantGetter('isIndexable', value=False) obj.isIndexable = ConstantGetter('isIndexable', value=False)
......
...@@ -1739,6 +1739,10 @@ class TemplateTool (BaseTool): ...@@ -1739,6 +1739,10 @@ class TemplateTool (BaseTool):
old_item._sign = -1 old_item._sign = -1
to_install_path_item_list.append(old_item) to_install_path_item_list.append(old_item)
# Update hashes of item in old state before installation
for item in old_installation_state._path_item_list:
item._sha = self.calculateComparableHash(item._value)
# Path Item List for installation_process should be the difference between # Path Item List for installation_process should be the difference between
# old and new installation state # old and new installation state
for item in new_installation_state._path_item_list: for item in new_installation_state._path_item_list:
...@@ -1765,6 +1769,27 @@ class TemplateTool (BaseTool): ...@@ -1765,6 +1769,27 @@ class TemplateTool (BaseTool):
installMultipleBusinessManager = updateInstallationState installMultipleBusinessManager = updateInstallationState
def calculateComparableHash(self, object):
"""
Remove some attributes before comparing hashses
and return hash of the comparable object dict
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 = object.__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))
return obj_sha
def compareOldStateToOFS(self, installation_process, old_state): def compareOldStateToOFS(self, installation_process, old_state):
# Get the paths about which we are concerned about # Get the paths about which we are concerned about
...@@ -1777,19 +1802,7 @@ class TemplateTool (BaseTool): ...@@ -1777,19 +1802,7 @@ class TemplateTool (BaseTool):
try: try:
obj = portal.restrictedTraverse(path) obj = portal.restrictedTraverse(path)
# Use shallow copy of the dict of the object at ZODB after removing obj_sha = self.calculateComparableHash(obj)
# 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 # Get item at old state
old_item = old_state.getBusinessItemByPath(path) old_item = old_state.getBusinessItemByPath(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