@@ -812,19 +812,21 @@ def _get_reverse_diff(self):
812812 elif action == 'values_changed' :
813813 r_diff [action ] = {}
814814 for path , path_info in info .items ():
815- r_diff [action ][path ] = {
815+ reverse_path = path_info ['new_path' ] if path_info .get ('new_path' ) else path
816+ r_diff [action ][reverse_path ] = {
816817 'new_value' : path_info ['old_value' ], 'old_value' : path_info ['new_value' ]
817818 }
818819 elif action == 'type_changes' :
819820 r_diff [action ] = {}
820821 for path , path_info in info .items ():
821- r_diff [action ][path ] = {
822+ reverse_path = path_info ['new_path' ] if path_info .get ('new_path' ) else path
823+ r_diff [action ][reverse_path ] = {
822824 'old_type' : path_info ['new_type' ], 'new_type' : path_info ['old_type' ],
823825 }
824826 if 'new_value' in path_info :
825- r_diff [action ][path ]['old_value' ] = path_info ['new_value' ]
827+ r_diff [action ][reverse_path ]['old_value' ] = path_info ['new_value' ]
826828 if 'old_value' in path_info :
827- r_diff [action ][path ]['new_value' ] = path_info ['old_value' ]
829+ r_diff [action ][reverse_path ]['new_value' ] = path_info ['old_value' ]
828830 elif action == 'iterable_item_moved' :
829831 r_diff [action ] = {}
830832 for path , path_info in info .items ():
@@ -907,6 +909,7 @@ def _from_flat_dicts(flat_dict_list):
907909 action = flat_dict .get ("action" )
908910 path = flat_dict .get ("path" )
909911 value = flat_dict .get ('value' )
912+ new_path = flat_dict .get ('new_path' )
910913 old_value = flat_dict .get ('old_value' , UnkownValueCode )
911914 if not action :
912915 raise ValueError ("Flat dict need to include the 'action'." )
@@ -920,6 +923,10 @@ def _from_flat_dicts(flat_dict_list):
920923 else :
921924 root_element = ('root' , GET )
922925 path_str = stringify_path (path , root_element = root_element ) # We need the string path
926+ if new_path and new_path != path :
927+ new_path = stringify_path (new_path , root_element = root_element )
928+ else :
929+ new_path = None
923930 if action not in result :
924931 result [action ] = {}
925932 if action in {'iterable_items_added_at_indexes' , 'iterable_items_removed_at_indexes' }:
@@ -937,14 +944,14 @@ def _from_flat_dicts(flat_dict_list):
937944 result [action ][path_str ] = value
938945 elif action == 'values_changed' :
939946 if old_value == UnkownValueCode :
940- result [action ][path_str ] = {'new_value' : value }
947+ result [action ][path_str ] = {'new_value' : value , 'new_path' : new_path }
941948 else :
942- result [action ][path_str ] = {'new_value' : value , 'old_value' : old_value }
949+ result [action ][path_str ] = {'new_value' : value , 'old_value' : old_value , 'new_path' : new_path }
943950 elif action == 'type_changes' :
944951 type_ = flat_dict .get ('type' , UnkownValueCode )
945952 old_type = flat_dict .get ('old_type' , UnkownValueCode )
946953
947- result [action ][path_str ] = {'new_value' : value }
954+ result [action ][path_str ] = {'new_value' : value , 'new_path' : new_path }
948955 for elem , elem_value in [
949956 ('new_type' , type_ ),
950957 ('old_type' , old_type ),
0 commit comments