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

Objects' default manager should be used rathern than "model.objects" #175

Open
JirkaV opened this issue Feb 5, 2021 · 5 comments
Open

Comments

@JirkaV
Copy link

JirkaV commented Feb 5, 2021

Easy audit signal handlers assume that all model instances are reachable via Model.objects.get(). This might not be the case when model manager for "objects" is redefined (e.g. for something like SoftDeletableManager in django-model-utils. If that's the case, easy audit signal handling can fail with DoesNotExist when trying to get old value, e.g. here:

            if not created:
                old_model = sender.objects.get(pk=instance.pk)

I think it could be worker around by using models' _default_manager, as described at https://docs.djangoproject.com/en/3.1/topics/db/managers/#django.db.models.Model._default_manager

@jheld
Copy link
Collaborator

jheld commented Feb 6, 2021

Will you have some time in the next couple weeks to implement a PR?

@JirkaV
Copy link
Author

JirkaV commented Feb 6, 2021

Yup, will try.

@JirkaV
Copy link
Author

JirkaV commented Feb 6, 2021

Created pull request :)

@JirkaV
Copy link
Author

JirkaV commented Apr 6, 2021

Any chance this would get merged? The PR is simple enough and should be non-controversial. Thank you!

@sgordon16
Copy link

sgordon16 commented Jul 23, 2024

I think it would be better to use _base_manager the default manager can still be filtering out records and might still raise an DoesNotExist exception.

Any update on this? looks like #176 is waiting on changes. It would be really helpful if the fix was merged.

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

No branches or pull requests

3 participants