Commit e4106ffd authored by Niklas Stefan Nolte's avatar Niklas Stefan Nolte 🔥 Committed by Rosen Matev
Browse files

Fix hash dependence on dict order

parent 0a813276
......@@ -26,6 +26,7 @@ except ImportError:
from cgi import escape as html_escape
import inspect
import re
import json
from GaudiKernel.ConfigurableMeta import ConfigurableMeta
......@@ -51,14 +52,12 @@ _UNIQUE_PREFIXES = defaultdict(lambda: 0)
def _hash_dict(d):
return hash(','.join([str(k) + '=' + str(v) for k, v in d.items()]))
def _hash_list(l):
return hash(','.join((str(i) for i in l)))
"""hash a dict with string keys"""
return hash(json.dumps(d, sort_keys=True))
def _get_args(func):
"""get the argument keys of a function"""
return inspect.getargspec(func).args
......@@ -363,12 +362,13 @@ class Algorithm(object):
# location this forms part of the algorithm's defined behaviour
# So, record when any output location is forced
if isinstance(outputs, dict):
forced_locations = [
str(output) for output in outputs.values()
forced_locations = {
key: str(output)
for key, output in outputs.items()
if isinstance(output, force_location)
forced_locations = []
forced_locations = dict()
#TOOLS ##############
_tools = _pop_tools(kwargs)
......@@ -448,18 +448,17 @@ class Algorithm(object):
def _calc_id(typename, props, inputs, tools, forced_outputs=None):
if forced_outputs is None:
forced_outputs = []
forced_outputs = dict()
props_hash = _hash_dict(props)
# TODO include the transformed input somehow
inputs_hash = _hash_dict(
{key: _datahandle_ids(handles)
for key, handles in inputs.items()})
tools_hash = _hash_dict({key: for key, tool in tools.items()})
outputs_hash = _hash_list(forced_outputs)
to_be_hashed = [
typename, props_hash, inputs_hash, tools_hash, outputs_hash
return _hash_list(to_be_hashed)
outputs_hash = _hash_dict(forced_outputs)
to_be_hashed = (typename, props_hash, inputs_hash, tools_hash,
return hash(to_be_hashed)
# end of __init__
......@@ -773,8 +772,8 @@ class Tool(object):
{key: _datahandle_ids(handles)
for key, handles in inputs.items()})
tools_hash = _hash_dict({key: for key, tool in tools.items()})
to_be_hashed = [typename, props_hash, inputs_hash, tools_hash]
return _hash_list(to_be_hashed)
to_be_hashed = (typename, props_hash, inputs_hash, tools_hash)
return hash(to_be_hashed)
def inputs(self):
Supports Markdown
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