deepdiff
deepdiff copied to clipboard
Fix for diffing using iterable_compare_func with nested objects.
@seperman we have been using deep diff with the iterable_compare_func I helped add a little while back and we ran into an issue with nested objects. If you had an iterable item that moved, and then it had a nested iterable item that got objects added - it was incorrectly merging those objects. So something like:
t1 = {
"TestTable": [
{
"id": "022fb580-800e-11ea-a361-39b3dada34b5",
"name": "Max",
"NestedTable": [
{
"id": "022fb580-800e-11ea-a361-39b3dada34a6",
"NestedField": "Test Field"
}
]
},
{
"id": "022fb580-800e-11ea-a361-12354656532",
"name": "Bob",
"NestedTable": [
{
"id": "022fb580-800e-11ea-a361-39b3dada34c7",
"NestedField": "Test Field 2"
},
]
},
]
}
t2 = {"TestTable": [
{
"id": "022fb580-800e-11ea-a361-12354656532",
"name": "Bob (Changed Name)",
"NestedTable": [
{
"id": "022fb580-800e-11ea-a361-39b3dada34c7",
"NestedField": "Test Field 2 (Changed Nested Field)"
},
{
"id": "new id",
"NestedField": "Test Field 3"
},
{
"id": "newer id",
"NestedField": "Test Field 4"
},
]
},
{
"id": "adding_some_random_id",
"name": "New Name",
"NestedTable": [
{
"id": "random_nested_id_added",
"NestedField": "New Nested Field"
},
{
"id": "random_nested_id_added2",
"NestedField": "New Nested Field2"
},
{
"id": "random_nested_id_added3",
"NestedField": "New Nested Field43"
},
]
}
]}
Merged the items in the t2 nested tables like this rather than splitting it across the item that was moved.
{
"TestTable": [
{
"NestedTable": [
{
"id": "random_nested_id_added",
"NestedField": "New Nested Field"
},
{
"id": "new id",
"NestedField": "Test Field 3"
},
{
"id": "newer id",
"NestedField": "Test Field 4"
}
],
"id": "adding_some_random_id",
"name": "New Name"
}
]
}
You can see these objects in the new test that was failing without these changes.
I have put comments on the two main changes describing them a bit more.