Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
redieroglif opened this issue Jun 29, 2023 · 1 comment · Fixed by mathspace/django-auditlog-v3#1

Comments

@redieroglif
Copy link

redieroglif commented Jun 29, 2023

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.

@hramezani
Copy link
Member

hramezani commented Jun 30, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants