Describe the bug
normalize_value_for_hashing method is not custom operator scoped, so that all normalize_value_for_hashing methods from all registered operators are invoked during comparison, ignoring match method result.
To Reproduce
- Create custom operator.
- Implement
match method so that it returns True on comparisons of str only.
- Implement
normalize_value_for_hashing any way so that you can set a breakpoint inside. (or add print)
- Compare two integers with
ignore_order = True in debug mode (so that match method returns False).
- Code stops in
normalize_value_for_hashing method.
Expected behavior
Since the operator should not be used in case of comparison of integers, normalize_value_for_hashing method from the operator should not be invoked.
Additional info:
Because of this behavior, if registered comparator has normalize_value_for_hashing with pass inside, comparison of lists is fully incorrect. E.g. [1, 2], [2, 3] - these lists are assumed as identical by deepdiff, even though the comparator above shouldnt have been invoked.
OS, DeepDiff version and Python version (please complete the following information):
- OS: MacOS 15.7.1
- Python Version 3.13.2
- DeepDiff Version 9.1.0
Example:
from typing import Any
from deepdiff import DeepDiff
from deepdiff.model import DiffLevel
from deepdiff.operator import BaseOperatorPlus
class StrCompareCustomOperator(BaseOperatorPlus):
def match(self, level: DiffLevel) -> bool:
return isinstance(level.t1, str) and isinstance(level.t2, str)
def give_up_diffing(self, level: DiffLevel, diff_instance: DeepDiff) -> bool:
actual = level.t2
expected = level.t1
return actual == expected
def normalize_value_for_hashing(self, parent: Any, obj: Any) -> Any:
pass
Describe the bug
normalize_value_for_hashingmethod is not custom operator scoped, so that allnormalize_value_for_hashingmethods from all registered operators are invoked during comparison, ignoring matchmethodresult.To Reproduce
matchmethod so that it returnsTrueon comparisons of str only.normalize_value_for_hashingany way so that you can set a breakpoint inside. (or add print)ignore_order = Truein debug mode (so thatmatchmethod returnsFalse).normalize_value_for_hashingmethod.Expected behavior
Since the operator should not be used in case of comparison of integers,
normalize_value_for_hashingmethod from the operator should not be invoked.Additional info:
Because of this behavior, if registered comparator has
normalize_value_for_hashingwithpassinside, comparison of lists is fully incorrect. E.g. [1, 2], [2, 3] - these lists are assumed as identical by deepdiff, even though the comparator above shouldnt have been invoked.OS, DeepDiff version and Python version (please complete the following information):
Example: