django-auditlog: Custom signal post_log is triggered even when LogEntry is not created

From https://github.com/jazzband/django-auditlog/blob/master/auditlog/receivers.py#L99

    try:
        changes = model_instance_diff(
            diff_old, diff_new, fields_to_check=fields_to_check
        )

        if force_log or changes:
            LogEntry.objects.log_create(
                instance,
                action=action,
                changes=changes,
                force_log=force_log,
            )
    except BaseException as e:
        error = e
    finally:
        post_log.send(
            sender,
            instance=instance,
            action=action,
            error=error,
            pre_log_results=pre_log_results,
        )
        if error:
            raise error

When changes is None implying that the model was saved with no changes, LogEntry object is not created, but the post_log signal is still being send in the finally block which shouldnt happen.

To reproduce the issue:

  1. Set any registered model with a receiver for the post_log signal to print a log
  2. Save an object without any changes

I am using the last master commit for this.

Another issue here is that the “Custom Signals” feature is not released yet but is part of the public documentation already - https://django-auditlog.readthedocs.io/en/latest/internals.html#custom-signals

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 17 (15 by maintainers)

Most upvoted comments

Hey @aabanaag, no, It will be available in V3. we are preparing a beta release for V3 and it will be available soon

‌ Understood, when is the next release with this change slated to happen?

It is not decided yet.

I will make the fix for this if I can get time by then.

That would be great!

Will also open a separate issue for the documentation problem.

@aqeelat created an issue already https://github.com/jazzband/django-auditlog/issues/538