Skip to content

group_by fails if group_by key is None #503

Open
@vmatt

Description

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

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