Skip to content

Custom operator applied to excluded path (diff correctly excludes comparison result) #633

Open

Description

@braingram

Describe the bug
Custom operator applied to excluded paths.

To Reproduce
Based off of one of the examples in the docs:

from deepdiff import DeepDiff
from deepdiff.operator import BaseOperator

class CustomClass:
    def __init__(self, d: dict, l: list):
        self.dict = d
        self.dict['list'] = l


custom1 = CustomClass(d=dict(a=1, b=2), l=[1, 2, 3])
custom2 = CustomClass(d=dict(c=3, d=4), l=[1, 2, 3, 2])
custom3 = CustomClass(d=dict(a=1, b=2), l=[1, 2, 3, 4])


class ListMatchOperator(BaseOperator):
    def give_up_diffing(self, level, diff_instance):
        print(f"Comparing {level.path()}")
        if set(level.t1.dict['list']) == set(level.t2.dict['list']):
            return True

t1 = {"a": custom1, "b": custom2}
t2 = {"a": custom1, "b": custom3}

print(DeepDiff(
    t1,
    t2,
    custom_operators=[ListMatchOperator(types=[CustomClass])],
    exclude_paths=["b"],
))

produces the output:

Comparing root['a']
Comparing root['b']
{}

showing that "b" was compared even though it was excluded (the comparison result was later ignored and not included in the diff output).

Expected behavior

Expected behavior is that excluded paths aren't compared. Alternatively this may be intended behavior (to allow custom operators to run on all paths).

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

  • OS: mac os
  • Version tahoe
  • Python Version 3.14.2
  • DeepDiff Version 9.1.0

Additional context
Add any other context about the problem here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions