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

_base_manager instead of objects #168

Closed

Conversation

gurkankisaoglu
Copy link

In our project default object managers are overridden in most of the models and we use the django-easy-audit repository in several places, this sometimes creates errors.
Error scenario:

  • We have User model and default object manager overridden for excluding inactive users from queryset.
  • Making change any model instance that a deactivated user is connected to triggers easy audit’s pre save signal to audit the change.
    -Easy audit is trying to log the change by creating a CRUDEvent instance but since we exclude inactive users in default object manager and easy audit uses object in their pre save signal, user is not found.

@jheld
Copy link
Collaborator

jheld commented Nov 25, 2020

Before I review this, could you check if the easy audit callback hook is used in pre-save? If so, I'd recommend you use that. If not...would adding it to the pre-save work?

@bugraaydin
Copy link

Before I review this, could you check if the easy audit callback hook is used in pre-save? If so, I'd recommend you use that. If not...would adding it to the pre-save work?

Hello @jheld could you elaborate easy audit callback hook please?

@jheld
Copy link
Collaborator

jheld commented Nov 25, 2020

Sure. There should be some references to: DJANGO_EASY_AUDIT_CRUD_DIFFERENCE_CALLBACKS

If set, it will call a function which tells easyaudit whether or not to create the CRUDEvent. Applications can leverage this to perform dynamic/complex decision about making an instance or not, with the correct context.

@gokberk-sahin
Copy link

gokberk-sahin commented Dec 31, 2020

Hello @jheld! The problem that we are having is an exception caused by we overriding the object manager to filter out the deactivated users. This causes the old_model = sender.objects.get(pk=instance.pk) throw a DoesNotExist exception before even checking for the callbacks. So I propose that we make the callback checks and return False early if necessary in #172 . I would appreciate if you take a look.

@JirkaV
Copy link

JirkaV commented Feb 25, 2021

Incidentally I didn't notice this and created #176 - the only difference is that I didn't feel the need to use _base_manager for Django ContentType.

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

Successfully merging this pull request may close these issues.

5 participants