Skip to content

Errors with dictionary_item_removed and dictionary_item_added #440

@tpcalhoun

Description

@tpcalhoun

Please checkout the F.A.Q page before creating a bug ticket to make sure it is not already addressed.

Describe the bug
When using a dictionary and a Delta containing either dictionary_item_removed or dictionary_item_added to generate a resulting dictionary, will cause the following error:
TypeError: 'list' object is not callable

To Reproduce
You can run this sample code to demonstrate both error conditions:

import pytest
import json
import copy
from deepdiff import DeepDiff, Delta

"""
Sample code (Unit Test) to demonstrate DeepDiff errors when trying
to generate a result dict from a starting dict + Delta
    
    execute:
    pytest -vv demo_deepdiff_fail.py
"""


def test_demonstrate_fail_dictionary_item_removed():
    """
    Demonstrate fail with:
    {'dictionary_item_removed': [root['individualCustomer']['employment']]}
    """
    dict1 = {"individualCustomer": {
        "gender": "Male",
        "citizenship": {
            "country": "United States"
        },
        "employment": {
            "employerName": "ABC LTD",
            "jobTitle": "Bookkeeper",
            "status": "Full-time"
        }
    }}

    # Make a copy of dict1
    dict2 = copy.deepcopy(dict1)
    # Remove the inner object employment from dict2 only.
    dict2['individualCustomer'].pop('employment')

    # find the difference between the two dictionaries
    # putting dict1 FIRST...
    updates = DeepDiff(dict1, dict2)
    updates_dict = updates.to_dict()

    # now using a Delta and dict1, try to generate dict2
    delta = Delta(updates_dict)
    generated_dict = dict1 + delta

    # ############################ #
    # Errors on statement above with:
    # E  TypeError: 'list' object is not callable
    # C:\DEV\Tools\Python\Python38\lib\site-packages\deepdiff\delta.py:466: TypeError
    # ############################ #

    assert dict2 == generated_dict

def test_demonstrate_fail_dictionary_item_added():
    """
    Demonstrate fail with:
    {'dictionary_item_added': [root['individualCustomer']['employment']]}
    """
    dict1 = {"individualCustomer": {
        "gender": "Male",
        "citizenship": {
            "country": "United States"
        },
        "employment": {
            "employerName": "ABC LTD",
            "jobTitle": "Bookkeeper",
            "status": "Full-time"
        }
    }}

    # Make a copy of dict1
    dict2 = copy.deepcopy(dict1)
    # Remove the inner object employment from dict2 only.
    dict2['individualCustomer'].pop('employment')

    # find the difference between the two dictionaries
    # putting dict2 FIRST...
    updates = DeepDiff(dict2, dict1)
    updates_dict = updates.to_dict()

    # now using a Delta and dict2, try to generate dict1
    delta = Delta(updates_dict)
    generated_dict = dict2 + delta

    # ############################ #
    # Errors on statement above with:
    # E   TypeError: 'list' object is not callable
    # C:\DEV\Tools\Python\Python38\lib\site-packages\deepdiff\delta.py:357: TypeError
    # ############################ #

    assert dict1 == generated_dict

Expected behavior
A clear and concise description of what you expected to happen.

OS, DeepDiff version and Python version (please complete the following information):

  • OS: [e.g. Ubuntu] Windows10
  • Version [e.g. 20LTS]
  • Python Version [e.g. 3.9.12] 3.8
  • DeepDiff Version [e.g. 5.8.0] 6.7.0

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions