django-auditlog icon indicating copy to clipboard operation
django-auditlog copied to clipboard

Empty GenericIPAddressField are stored as Null/None and always show up in the changes

Open stoffi92 opened this issue 7 years ago • 0 comments

Because empty (empty string) GenericIPAddressFields if saved via a form are stored as Null value in the database (not as an empty string) and on retrieval via the ORM are represented as None values. Empty GenericIPAddressFields always show up as changes in the auditlog:

The field in the model is defined as following:

ip = GenericIPAddressField(null=True, blank=True, verbose_name='IP Address')

The auditlog on each save (without changes) that contain a empty string for IP address shows (even though the IP was empty before):

ip: None →

In diff.py I added the following 2 lines in get_field_value to fix this problem:

        try:
            value = smart_text(getattr(obj, field.name, None))
+           if isinstance(field, GenericIPAddressField) and not value:
+              value = smart_text(None)
        except ObjectDoesNotExist:

stoffi92 avatar Nov 05 '18 08:11 stoffi92