mirror of
https://github.com/jazzband/django-auditlog.git
synced 2026-03-16 22:20:26 +00:00
Stop deleting log entries in log_create (#559)
This commit is contained in:
parent
af31261946
commit
ac737fd55c
3 changed files with 3 additions and 21 deletions
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
#### 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
|
||||
|
||||
#### Fixes
|
||||
|
|
|
|||
|
|
@ -66,26 +66,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 a 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:
|
||||
update_fields = kwargs.get("update_fields", None)
|
||||
old = sender.objects.filter(pk=instance.pk).first()
|
||||
_create_log_entry(
|
||||
|
|
|
|||
Loading…
Reference in a new issue