mirror of
https://github.com/jazzband/django-auditlog.git
synced 2026-05-14 18:43:11 +00:00
Stop deleting log entries in log_create
This commit is contained in:
parent
682e8e270b
commit
47188b46d7
3 changed files with 5 additions and 21 deletions
|
|
@ -2,6 +2,10 @@
|
|||
|
||||
## Next Release
|
||||
|
||||
#### Breaking Changes
|
||||
|
||||
- feat: stop deleting old log entries when a model with the same pk is created (i.e. the pk value is reused) ([#559](https://github.com/jazzband/django-auditlog/pull/559))
|
||||
|
||||
#### Improvements
|
||||
|
||||
- feat: Added support for Correlation ID
|
||||
|
|
|
|||
|
|
@ -59,26 +59,6 @@ class LogEntryManager(models.Manager):
|
|||
if callable(get_additional_data):
|
||||
kwargs.setdefault("additional_data", get_additional_data())
|
||||
|
||||
# Delete log entries with the same pk as a newly created model.
|
||||
# This should only be necessary when an pk is used twice.
|
||||
if kwargs.get("action", None) is LogEntry.Action.CREATE:
|
||||
if (
|
||||
kwargs.get("object_id", None) is not None
|
||||
and self.filter(
|
||||
content_type=kwargs.get("content_type"),
|
||||
object_id=kwargs.get("object_id"),
|
||||
).exists()
|
||||
):
|
||||
self.filter(
|
||||
content_type=kwargs.get("content_type"),
|
||||
object_id=kwargs.get("object_id"),
|
||||
).delete()
|
||||
else:
|
||||
self.filter(
|
||||
content_type=kwargs.get("content_type"),
|
||||
object_pk=kwargs.get("object_pk", ""),
|
||||
).delete()
|
||||
|
||||
# set correlation id
|
||||
kwargs.setdefault("cid", get_cid())
|
||||
return self.create(**kwargs)
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ def log_update(sender, instance, **kwargs):
|
|||
|
||||
Direct use is discouraged, connect your model through :py:func:`auditlog.registry.register` instead.
|
||||
"""
|
||||
if instance.pk is not None:
|
||||
if not instance._state.adding:
|
||||
try:
|
||||
old = sender.objects.get(pk=instance.pk)
|
||||
except sender.DoesNotExist:
|
||||
|
|
|
|||
Loading…
Reference in a new issue