Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RecursionError with custom objects #400

Open
chasel2361 opened this issue Jun 30, 2023 · 2 comments
Open

RecursionError with custom objects #400

chasel2361 opened this issue Jun 30, 2023 · 2 comments
Labels

Comments

@chasel2361
Copy link

I' not sure is this a bug or not. Maybe someone can give me some hint to fix this problem.

Describe the bug
I have a custom Node object with the following structure:

class Node():
    def __init__(self, row, level):
        
        self.level = level
        self.DESC = row['Description']
        self.id = {
            'HP': row[col_by_level[level][0]], 
            'IEC': row[col_by_level[level][1]],
        }
        self.Quantity = row['Quantity']
        self.children = []
        self.parent = None
        self.classification = None
    
    def __repr__(self):
        return f'{self.__class__.__name__} {self.id}: {self.DESC}'
    def add_child(self, node):
        node.set_parent(self)
        self.children.append(node)
    def set_parent(self, node):
        self.parent = node

When I compare these two objects, it enters an infinite loop with specific data content.

To Reproduce
I have already used pickle to save the data that will cause errors as an attachment.
Node.zip

with open('N344.pickle', 'rb') as f:
    n_old344, n_new344 = pickle.load(f)
with open('N437.pickle', 'rb') as f:
    n_old437, n_new437 = pickle.load(f)

DeepDiff(n_old344, n_new344, ignore_order=True)

Buggy Output
RecursionError: maximum recursion depth exceeded
the infinite loop is in Node.children

Expected behavior

{'values_changed': {'root.Quantity': {'new_value': nan, 'old_value': nan},
  "root.children[4].children[0].id['HP']": {'new_value': 'L48869-AE2',
   'old_value': 'L48869-372'},
  "root.children[4].children[0].id['IEC']": {'new_value': '6061B1252520',
   'old_value': '6061B1252515'},
  "root.children[4].children[0].children[0].id['HP']": {'new_value': 'L48870-AE2',
   'old_value': 'L48870-372'},
  "root.children[4].children[0].children[0].id['IEC']": {'new_value': 'L48870-AE2',
   'old_value': 'L48870-372'}}}

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

  • OS: Windows
  • Version 10
  • Python Version 3.11.3
  • DeepDiff Version 6.3.0

Additional context

@seperman
Copy link
Owner

seperman commented Jul 6, 2023

oops. I see you have already opened a ticket for it.

@seperman
Copy link
Owner

seperman commented Jul 6, 2023

@chasel2361 Thanks for posting reproducible code. Is it possible to give me the smallest amount of data that causes the issue? That way I can add it as a unit test to make sure the issue is resolved once and for all.

@seperman seperman added the bug label Jul 6, 2023
@seperman seperman changed the title deepdiff works wierd while comparing two user defined tree with iignore_order=True RecursionError with custom objects Jul 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants