django-auditlog/auditlog_tests
August Raack c649629225
Change diff to evaluate PKs for FK relationships (#420)
* 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
2022-12-28 09:51:44 +01:00
..
fixtures Added support for Correlation ID 2022-12-23 15:09:32 +01:00
templates Added ACCESS action and enabled logging of object accesses (#436) 2022-11-07 08:51:00 +01:00
__init__.py Remove default_app_config configuration 2022-05-02 14:48:58 +02:00
admin.py Use admin for test site 2020-09-07 16:52:32 +02:00
apps.py Add black and format files with black. 2020-12-06 23:10:18 +01:00
manage.py Clean up project structure 2020-09-07 16:52:32 +02:00
models.py Change diff to evaluate PKs for FK relationships (#420) 2022-12-28 09:51:44 +01:00
test_commands.py Add flake8 to pre-commit config (#387) 2022-06-18 20:50:25 +04:30
test_settings.py Switch MIDDLEWARE from a tuple to a list 2022-06-28 19:20:02 +02:00
tests.py Change diff to evaluate PKs for FK relationships (#420) 2022-12-28 09:51:44 +01:00
urls.py Added ACCESS action and enabled logging of object accesses (#436) 2022-11-07 08:51:00 +01:00
views.py Added ACCESS action and enabled logging of object accesses (#436) 2022-11-07 08:51:00 +01:00