django-auditlog
django-auditlog copied to clipboard
Reverse relations are being logged
One issue we came across with auditlog is that we're registering all fields including reverse-related fields. Which means that:
- we'll be hitting the db multiple times since these fields might not be pre-fetched in the QuerySet
- we'll be updating
instance._state.fields_cacheas a side effect, which is not a documented behavior.
I will open a PR to soon to show a possible fix for the issue.
@hramezani
Sorry I didn't get around to the pr.
The issue is that when we're calling .get_fields() in diff.py, we're getting the auto created fields.
Maybe we can exclude them when we're registering the models.
for field in meta.get_fields():
if isinstance(field, ManyToManyField):
m2m_fields.append(field.name)
elif field.auto_created and isinstance(field, ForeignObjectRel):
exclude_fields.append(field.name)
@aqeelat can we have a config flag for this? Something like exclude_reverse_relation. The default value can be False to don't change the old behavior.