diff --git a/deepdiff/diff.py b/deepdiff/diff.py index 45f0328..a6fe06b 100755 --- a/deepdiff/diff.py +++ b/deepdiff/diff.py @@ -1846,9 +1846,13 @@ def affected_root_keys(self): value = self.tree.get(key) if value: if isinstance(value, SetOrdered): - result |= SetOrdered([i.get_root_key() for i in value]) + values_list = value else: - result |= SetOrdered([i.get_root_key() for i in value.keys()]) + values_list = value.keys() + for item in values_list: + root_key = item.get_root_key() + if root_key is not notpresent: + result.add(root_key) return result diff --git a/deepdiff/model.py b/deepdiff/model.py index 298824a..f5e5a4d 100644 --- a/deepdiff/model.py +++ b/deepdiff/model.py @@ -665,7 +665,9 @@ def get_root_key(self, use_t2=False): else: next_rel = root_level.t1_child_rel or root_level.t2_child_rel # next relationship object to get a formatted param from - return next_rel.param + if next_rel: + return next_rel.param + return notpresent def path(self, root="root", force=None, get_parent_too=False, use_t2=False, output_format='str'): """ diff --git a/tests/test_diff_text.py b/tests/test_diff_text.py index 4de67b2..63df30a 100755 --- a/tests/test_diff_text.py +++ b/tests/test_diff_text.py @@ -807,6 +807,24 @@ class ClassB: result = {'attribute_removed': ['root.y']} assert result == ddiff + def test_custom_objects_slot_in_group_change(self): + class ClassA: + __slots__ = ('x', 'y') + + def __init__(self, x, y): + self.x = x + self.y = y + + class ClassB(ClassA): + pass + + t1 = ClassA(1, 1) + t2 = ClassB(1, 1) + ddiff = DeepDiff(t1, t2, ignore_type_in_groups=[(ClassA, ClassB)]) + result = {} + assert result == ddiff + + def test_custom_class_changes_none_when_ignore_type(self): ddiff1 = DeepDiff({'a': None}, {'a': 1}, ignore_type_subclasses=True, ignore_type_in_groups=[(int, float)]) result = { @@ -2226,3 +2244,10 @@ def test_group_by_with_none_key_and_ignore_case(self): } } assert expected == diff + + def test_affected_root_keys_when_dict_empty(self): + diff = DeepDiff({}, {1:1, 2:2}, threshold_to_diff_deeper=0) + assert [1, 2] == diff.affected_root_keys + + diff2 = DeepDiff({}, {1:1, 2:2}) + assert [] == diff2.affected_root_keys