-
-
Notifications
You must be signed in to change notification settings - Fork 255
Description
Describe the bug
DeepDiff fails when 2 new fields are added in t2 in different nested dictionary fields. The library identifies correctly the name of the new fields, but it is unable to retrieve the correct dictionary levels or paths to them.
DeepDiff works as expected when just a new field is added, but it breaks when 2 new fields are added in different levels.
To Reproduce
Create two dictionaries to compare:
s1 = {
"type": "struct",
"fields": [
{"name": "Competition", "metadata": {}, "nullable": True, "type": "string"},
{"name": "TeamName", "metadata": {}, "nullable": True, "type": "string"},
{
"name": "Contents",
"metadata": {},
"nullable": True,
"type": {
"type": "struct",
"fields": [
{"name": "Date", "metadata": {}, "nullable": True, "type": "string"},
{"name": "Player1", "metadata": {}, "nullable": True, "type": "string"}
]
}
}
]
}
s2 = {
"type": "struct",
"fields": [
{"name": "Competition", "metadata": {}, "nullable": True, "type": "string"},
{"name": "GlobalId", "metadata": {}, "nullable": True, "type": "string"},
{"name": "TeamName", "metadata": {}, "nullable": True, "type": "string"},
{
"name": "Contents",
"metadata": {},
"nullable": True,
"type": {
"type": "struct",
"fields": [
{"name": "Date", "metadata": {}, "nullable": True, "type": "string"},
{"name": "Player1", "metadata": {}, "nullable": True, "type": "string"},
{"name": "Player2", "metadata": {}, "nullable": True, "type": "string"}
]
}
}
]
}
The s2 dictionary contains two new fields GlobalId at root['fields'][1] and Player2 at root['fields'][3]['type']['fields'][2], but if I run
dd = DeepDiff(t1=s1, t2=s2, ignore_order=True, verbose_level=2)
I get:
{
'iterable_item_added': {
"root['fields'][1]": {'name': 'GlobalId', 'metadata': {}, 'nullable': True, 'type': 'string'},
"root['fields'][2]['type']['fields'][2]": {'name': 'Player2', 'metadata': {}, 'nullable': True, 'type': 'string'}
}
}
Which is wrong for the second added field: the new field name is correctly identified, but the path within the dictionary is wrong, the path root['fields'][2]['type']['fields'][2] does not exist.
Expected behavior
It should return the right dictionary path for the second added field, that is root['fields'][3]['type']['fields'][2], i.e., the full correct output should be:
{
'iterable_item_added': {
"root['fields'][1]": {'name': 'GlobalId', 'metadata': {}, 'nullable': True, 'type': 'string'},
"root['fields'][3]['type']['fields'][2]": {'name': 'Player2', 'metadata': {}, 'nullable': True, 'type': 'string'}
}
}
OS, DeepDiff version and Python version (please complete the following information):
- OS: Linux
- Version: Any
- Python Version 3.8
- DeepDiff Version > 6.5.0 (tested with 6.5.1 and 6.7.1).
Additional context
None.