From b056c58cbfff6e7bc31a52a3a9fcc7f911a2023d Mon Sep 17 00:00:00 2001 From: Lukas Holecek Date: Nov 19 2019 13:46:13 +0000 Subject: Fix order of requirements in decision Signed-off-by: Lukas Holecek --- diff --git a/greenwave/policies.py b/greenwave/policies.py index e9b6536..ecb6934 100644 --- a/greenwave/policies.py +++ b/greenwave/policies.py @@ -8,7 +8,7 @@ import re import greenwave.resources from werkzeug.exceptions import BadRequest from flask import current_app -from greenwave.utils import remove_duplicates, to_hashable +from greenwave.utils import remove_duplicates from greenwave.safe_yaml import ( SafeYAMLBool, SafeYAMLChoice, @@ -69,9 +69,6 @@ class Answer(object): """ raise NotImplementedError() - def __hash__(self): - return hash(to_hashable(self.to_json())) - def __eq__(self, other): try: json1 = self.to_json() diff --git a/greenwave/utils.py b/greenwave/utils.py index c979a5d..5a73d88 100644 --- a/greenwave/utils.py +++ b/greenwave/utils.py @@ -145,18 +145,13 @@ def right_before_this_time(timestamp): def remove_duplicates(func): def wrapper(*args, **kwargs): - rv = func(*args, **kwargs) - if isinstance(rv, list) and len(rv): - rv = list(set(rv)) - return rv + value = func(*args, **kwargs) + if not isinstance(value, list): + return value + + unique = [] + for item in value: + if item not in unique: + unique.append(item) + return unique return wrapper - - -def to_hashable(val): - if isinstance(val, list) or isinstance(val, tuple): - return tuple([to_hashable(v) for v in val]) - if isinstance(val, dict): - return tuple([(k, to_hashable(val[k])) for k in sorted(val.keys())]) - if isinstance(val, set): - return tuple(sorted(val)) - return val