* Refactor: re-arrange test application
This was triggered by the need to run "python manage.py", which is impossible when serving the whole project in the same directory as is configured in INSTALLED_APPS ("auditlog_tests"). This setup is heavily inspired by other jazzband projects.
* Add check for missing migrations
* fix: use sender for m2m signal dispatch connection
This fix adds support for a use case where a single m2m through model is
used on multiple models. When the reciever is used for the dispatch uid
in this use case it cause duplicated logs because the through model
singal connection happens multiple times.
By changing the m2m signal connection to use the sender for the dispatch
uid this duplication is prevented because the signal connection only
happens once for the through model.
Refs: #685
* fix(format): apply black formatting
* add test and changelog entry
* remove unused import
* correct import sorting
* move change log message to correct section
* Use `attname` to get pk value
* Add tests for model as primary key
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Add clarifying comments to _get_pk_value
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Fix serialize __proxy__ objects before logging
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update CHANGELOG.md
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>
This is a breaking change. The default behavior is to delete the
related objects, but it doesn't make sense to apply it to audit log
entries, at least not by default.
* Change diff to evaluate PKs for FK relationships
The diff method now evaluates the primary keys for changes to determine
if a new LogEntry should be created. Previously, the diff method was
evaluating the string representation of the object. This was flawed
because cases can occur when a parent object has in memory changes to
its string string representation and the child related object is saved
prior to these in memory changes being persisted. In these cases a new
LogEntry object would be created erroneously. This cases is asserted
with a test and a regression test will verify the bug.
The consequence of these updates is that the ``LogEntry.changes`` field
now stores primary keys rather than string representations for related
objects. To keep the changes dictionary display unaffected by this
update, a method was added to the ``LogEntry`` model. This method looks
up the object display string from the stored foreign key. Exceptions
were written to handle backwards compatibility.
* Added test case to cover another bug
Because the string representation is not unique for every object, relying
on it to determine FK diffs may not capture all changes. This test case
shows another type of scenario that is fixed by comparing primary keys
rather than object string representations. This is likely occurring
fairly regularly but is hard to spot because it is an error of omission.
* Update to docstring and added changelog