Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed manuall logging when model is not registered #627

Merged
merged 2 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
#### Fixes

- Fixed logging problem related to django translation before logging ([#624](https://github.com/jazzband/django-auditlog/pull/624))
- Fixed manuall logging when model is not registered ([#627](https://github.com/jazzband/django-auditlog/pull/627))

#### Improvements
- feat: Excluding ip address when `AUDITLOG_DISABLE_REMOTE_ADDR` is set to True ([#620](https://github.com/jazzband/django-auditlog/pull/620))

## 3.0.0-beta.4 (2024-01-02)

#### Improvements
- feat: Excluding ip address when `AUDITLOG_DISABLE_REMOTE_ADDR` is set to True ([#620](https://github.com/jazzband/django-auditlog/pull/620))

- feat: If any receiver returns False, no logging will be made. This can be useful if logging should be conditionally enabled / disabled ([#590](https://github.com/jazzband/django-auditlog/pull/590))
- Django: Confirm Django 5.0 support ([#598](https://github.com/jazzband/django-auditlog/pull/598))
- Django: Drop Django 4.1 support ([#598](https://github.com/jazzband/django-auditlog/pull/598))
Expand Down
3 changes: 3 additions & 0 deletions auditlog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ def _get_pk_value(self, instance):
def _get_serialized_data_or_none(self, instance):
from auditlog.registry import auditlog

if not auditlog.contains(instance.__class__):
return None

opts = auditlog.get_serialize_options(instance.__class__)
if not opts["serialize_data"]:
return None
Expand Down
15 changes: 15 additions & 0 deletions auditlog_tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,21 @@ def test_unregister_delete(self):
# Check for log entries
self.assertEqual(LogEntry.objects.count(), 0, msg="There are no log entries")

def test_manual_logging(self):
obj = self.obj
obj.boolean = True
obj.save()
LogEntry.objects.log_create(
instance=obj,
action=LogEntry.Action.UPDATE,
changes="",
)
self.assertEqual(
obj.history.filter(action=LogEntry.Action.UPDATE).count(),
1,
msg="There is one log entry for 'UPDATE'",
)


class RegisterModelSettingsTest(TestCase):
def setUp(self):
Expand Down