Skip to content

Commit 3d3bfd8

Browse files
committed
fixing more edge cases
1 parent dfe1ea5 commit 3d3bfd8

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

deepdiff/delta.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -944,14 +944,14 @@ def _from_flat_dicts(flat_dict_list):
944944
result[action][path_str] = value
945945
elif action == 'values_changed':
946946
if old_value == UnkownValueCode:
947-
result[action][path_str] = {'new_value': value, 'new_path': new_path}
947+
result[action][path_str] = {'new_value': value}
948948
else:
949-
result[action][path_str] = {'new_value': value, 'old_value': old_value, 'new_path': new_path}
949+
result[action][path_str] = {'new_value': value, 'old_value': old_value}
950950
elif action == 'type_changes':
951951
type_ = flat_dict.get('type', UnkownValueCode)
952952
old_type = flat_dict.get('old_type', UnkownValueCode)
953953

954-
result[action][path_str] = {'new_value': value, 'new_path': new_path}
954+
result[action][path_str] = {'new_value': value}
955955
for elem, elem_value in [
956956
('new_type', type_),
957957
('old_type', old_type),
@@ -960,13 +960,9 @@ def _from_flat_dicts(flat_dict_list):
960960
if elem_value != UnkownValueCode:
961961
result[action][path_str][elem] = elem_value
962962
elif action == 'iterable_item_moved':
963-
result[action][path_str] = {
964-
'new_path': stringify_path(
965-
flat_dict.get('new_path', ''),
966-
root_element=('root', GET)
967-
),
968-
'value': value,
969-
}
963+
result[action][path_str] = {'value': value}
964+
if new_path:
965+
result[action][path_str]['new_path'] = new_path
970966

971967
return result
972968

deepdiff/diff.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,7 +1280,13 @@ def get_other_pair(hash_value, in_t1=True):
12801280
other = get_other_pair(hash_value)
12811281
item_id = id(other.item)
12821282
indexes = t2_hashtable[hash_value].indexes if other.item is notpresent else other.indexes
1283-
index2 = t2_hashtable[hash_value].indexes[0]
1283+
# When we report repetitions, we want the child_relationship_param2 only if there is no repetition.
1284+
# Because when there is a repetition, we report it in a different way (iterable_items_added_at_indexes for example).
1285+
# When there is no repetition, we want child_relationship_param2 so that we report the "new_path" correctly.
1286+
if len(t2_hashtable[hash_value].indexes) == 1:
1287+
index2 = t2_hashtable[hash_value].indexes[0]
1288+
else:
1289+
index2 = None
12841290
for i in indexes:
12851291
change_level = level.branch_deeper(
12861292
other.item,
@@ -1299,7 +1305,13 @@ def get_other_pair(hash_value, in_t1=True):
12991305
return # pragma: no cover. This is already covered for addition.
13001306
other = get_other_pair(hash_value, in_t1=False)
13011307
item_id = id(other.item)
1302-
index2 = None if other.item is notpresent else other.indexes[0]
1308+
# When we report repetitions, we want the child_relationship_param2 only if there is no repetition.
1309+
# Because when there is a repetition, we report it in a different way (iterable_items_added_at_indexes for example).
1310+
# When there is no repetition, we want child_relationship_param2 so that we report the "new_path" correctly.
1311+
if other.item is notpresent or len(other.indexes > 1):
1312+
index2 = None
1313+
else:
1314+
index2 = other.indexes[0]
13031315
for i in t1_hashtable[hash_value].indexes:
13041316
change_level = level.branch_deeper(
13051317
t1_hashtable[hash_value].item,

tests/test_delta.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,10 +1020,12 @@ def test_delta_cases(self, test_name, t1, t2, deepdiff_kwargs, to_delta_kwargs,
10201020
},
10211021
'values_changed': {
10221022
'root[6]': {
1023-
'new_value': 7
1023+
'new_value': 7,
1024+
'new_path': 'root[0]',
10241025
},
10251026
'root[0]': {
1026-
'new_value': 8
1027+
'new_value': 8,
1028+
'new_path': 'root[6]',
10271029
}
10281030
}
10291031
},

0 commit comments

Comments
 (0)