django-easy-audit icon indicating copy to clipboard operation
django-easy-audit copied to clipboard

exception when use m2m clear() function

Open anemology opened this issue 4 years ago • 2 comments
trafficstars

error log

# ../bin/python3 manage.py shell
Python 3.8.0 (default, May  7 2020, 02:49:39) 
[GCC 8.3.1 20191121 (Red Hat 8.3.1-5)] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from account.models import Role
>>> a = Role.objects.first()
>>> a.jdbc.clear()
easy audit had a m2m_changed exception on CRUDEvent creation. instance: Role object (1), instance pk: 1
Traceback (most recent call last):
  File "/var/www/django/myapp/easyaudit/signals/model_signals.py", line 265, in crud_flow
    changed_fields = json.dumps({get_m2m_field_name(model, instance): list(pk_set)}, cls=DjangoJSONEncoder)
TypeError: 'NoneType' object is not iterable

https://docs.djangoproject.com/en/3.1/ref/signals/#m2m-changed I found the document, when action is post_clear, the pk_set will be None. May be we can add another event_type for m2m clear? And write changed_fields with empty list. If it is ok, I can submit a pull request for this fix.

anemology avatar Dec 18 '20 13:12 anemology

Hi. I'm not positive on having a new event_type but definitely agree on getting this fixed. Send up your PR when you have some time and let's find out if we can resolve the issue with or without a new event_type (end result is we fix it either way).

jheld avatar Jan 23 '21 03:01 jheld

@jheld I'm running into this issue also. Can you take a look at my PR?

AriAbr avatar Jan 10 '22 16:01 AriAbr