diff --git a/global_helpers/global_helpers_test.py b/global_helpers/global_helpers_test.py index f57b725b8..7a4262b07 100755 --- a/global_helpers/global_helpers_test.py +++ b/global_helpers/global_helpers_test.py @@ -9,6 +9,7 @@ import string import sys import unittest +from collections.abc import Sequence from panther_core.enriched_event import PantherEvent from panther_core.immutable import ImmutableCaseInsensitiveDict, ImmutableList @@ -1420,7 +1421,11 @@ def test_deep_walk_success_random(self): """ for _ in range(1000): data, keys, expected = self.generate_random_test_case_success() - self.assertEqual(p_b_h.deep_walk(data, *keys, default=""), expected) + result = p_b_h.deep_walk(data, *keys, default="") + if isinstance(result, Sequence) and not isinstance(result, str): + self.assertEqual(set(result), {expected}) + else: + self.assertEqual(result, expected) def test_deep_walk_default_random(self): """ @@ -1497,7 +1502,7 @@ def test_deep_walk_manual(self): p_b_h.deep_walk( event, "key", "very_nested", "outer_key", "nested_key2", "nested_key3", default="" ), - "value2", + ["value2", "value2"], ) self.assertEqual( p_b_h.deep_walk(event, "key", "very_nested", "outer_key2", "nested_key4", default=""), diff --git a/global_helpers/panther_base_helpers.py b/global_helpers/panther_base_helpers.py index 4f3260939..000c91070 100644 --- a/global_helpers/panther_base_helpers.py +++ b/global_helpers/panther_base_helpers.py @@ -1,7 +1,6 @@ import re from base64 import b64decode from binascii import Error as AsciiError -from collections import OrderedDict from collections.abc import Mapping from datetime import datetime from fnmatch import fnmatch @@ -73,7 +72,7 @@ def _empty_list(sub_obj: Any): return default if _empty_list(obj) else obj current_key = keys[0] - found: OrderedDict = OrderedDict() + found_list: list[Any] = [] if isinstance(obj, Mapping): next_key = obj.get(current_key, None) @@ -87,12 +86,10 @@ def _empty_list(sub_obj: Any): value = deep_walk(item, *keys, default=default, return_val=return_val) if value is not None: if isinstance(value, Sequence) and not isinstance(value, str): - for sub_item in value: - found[sub_item] = None + found_list.extend(value) else: - found[value] = None + found_list.append(value) - found_list: list[Any] = list(found.keys()) if not found_list: return default return {