deepdiff icon indicating copy to clipboard operation
deepdiff copied to clipboard

group_by fails if group_by key is None

Open vmatt opened this issue 1 year ago • 0 comments

Describe the bug When using group_by using a key which is nullable, it cannot do group_by on None, because of this line in diff.py

if self.ignore_string_case:
        clean_key = clean_key.lower()

AttributeError: 'NoneType' object has no attribute 'lower'

To Reproduce

from deepdiff import DeepDiff

# First dictionary
dict1 =[{'txt_field': 'FULL', 'group_id': None}]

# Second dictionary with some differences
dict2 = [{'txt_field': 'FULL', 'group_id': 'a'}]

# Compare the dictionaries
diff = DeepDiff(
    dict1,
    dict2,
    ignore_order=True,
    group_by='group_id',
    ignore_numeric_type_changes=True,
    significant_digits=1,
    ignore_string_case=True,
    ignore_nan_inequality=True,

)

print("Differences found:", diff)

Expected behavior If the group_by key is None, it should group_by all None/NULL fields where the group_by key is instance of string.

if self.ignore_string_case and isinstance(clean_key,str):
        clean_key = clean_key.lower()

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

  • OS: MacOS
  • Version: 15
  • Python Version: 3.11
  • DeepDiff Version: 8.0.1

vmatt avatar Nov 18 '24 10:11 vmatt