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

Reverse relations are being logged #551

Open
aqeelat opened this issue Jul 25, 2023 · 2 comments
Open

Reverse relations are being logged #551

aqeelat opened this issue Jul 25, 2023 · 2 comments

Comments

@aqeelat
Copy link
Member

aqeelat commented Jul 25, 2023

One issue we came across with auditlog is that we're registering all fields including reverse-related fields. Which means that:

  1. we'll be hitting the db multiple times since these fields might not be pre-fetched in the QuerySet
  2. we'll be updating instance._state.fields_cache as a side effect, which is not a documented behavior.

I will open a PR to soon to show a possible fix for the issue.

@aqeelat
Copy link
Member Author

aqeelat commented Aug 13, 2023

@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)

@hramezani
Copy link
Member

@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.

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

When branches are created from issues, their pull requests are automatically linked.

2 participants