django-easy-audit icon indicating copy to clipboard operation
django-easy-audit copied to clipboard

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

Open JirkaV opened this issue 4 years ago • 5 comments
trafficstars

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

JirkaV avatar Feb 05 '21 10:02 JirkaV

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

jheld avatar Feb 06 '21 01:02 jheld

Yup, will try.

JirkaV avatar Feb 06 '21 10:02 JirkaV

Created pull request :)

JirkaV avatar Feb 06 '21 20:02 JirkaV

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

JirkaV avatar Apr 06 '21 06:04 JirkaV