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

Many2many changes contain all model instances in 'objects' when using clear()

Open redieroglif opened this issue 2 years ago • 1 comments

When using MyModel.many2many_field.clear(), changes json looks like

{'many2many_field': {'type': 'm2m', 'operation': 'delete', 'objects': ['object1', 'object2', ... , 'object999999']}}

This can make changes field extremely big.

Maybe instead

if action == "post_clear":
    changed_queryset = kwargs["model"].objects.all()

you should use

if action == "pre_clear":
    changed_queryset = getattr(kwargs["model"], field_name).all()

in make_log_m2m_changes reciever.

Or alternatively just set operation to "clear" with empty objects list.

redieroglif avatar Jun 29 '23 08:06 redieroglif

Thanks @redieroglif for reporting this.

Another option would be to limit the objects to the first 10 or 20.

I think we can define a config with the default value of None. Then the user can limit it by changing the config value.

We can name the config AUDITLOG_M2M_LOG_OBJECTS_COUNT or whatever you prefer

hramezani avatar Jun 30 '23 14:06 hramezani