mirror of
https://github.com/jazzband/django-auditlog.git
synced 2026-03-16 22:20:26 +00:00
Fix serialize __proxy__ objects before logging
This commit is contained in:
parent
a0ae594425
commit
39bd421d9b
4 changed files with 17 additions and 1 deletions
|
|
@ -1,6 +1,7 @@
|
|||
# Changes
|
||||
|
||||
## Next Release
|
||||
- Fixed logging problem related to django translation before logging ([#624](https://github.com/jazzband/django-auditlog/pull/624))
|
||||
|
||||
## 3.0.0-beta.4 (2024-01-02)
|
||||
|
||||
|
|
|
|||
|
|
@ -82,6 +82,8 @@ def get_field_value(obj, field):
|
|||
)
|
||||
else:
|
||||
value = smart_str(getattr(obj, field.name, None))
|
||||
if type(value).__name__ == "__proxy__":
|
||||
value = str(value)
|
||||
except ObjectDoesNotExist:
|
||||
value = (
|
||||
field.default
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ class SimpleModel(models.Model):
|
|||
history = AuditlogHistoryField(delete_related=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.text
|
||||
return str(self.text)
|
||||
|
||||
|
||||
class AltPrimaryKeyModel(models.Model):
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ from django.urls import resolve, reverse
|
|||
from django.utils import dateformat, formats
|
||||
from django.utils import timezone as django_timezone
|
||||
from django.utils.encoding import smart_str
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from auditlog.admin import LogEntryAdmin
|
||||
from auditlog.cid import get_cid
|
||||
|
|
@ -1641,6 +1642,18 @@ class DiffMsgTest(TestCase):
|
|||
),
|
||||
)
|
||||
|
||||
def test_instance_translation_and_history_logging(self):
|
||||
first = SimpleModel()
|
||||
second = SimpleModel(text=_("test"))
|
||||
changes = model_instance_diff(first, second)
|
||||
self.assertEqual(
|
||||
changes,
|
||||
{'text': ('', 'test')}
|
||||
)
|
||||
second.save()
|
||||
log_one = second.history.last()
|
||||
self.assertTrue(isinstance(log_one, LogEntry))
|
||||
|
||||
def test_changes_msg_create(self):
|
||||
log_entry = self._create_log_entry(
|
||||
LogEntry.Action.CREATE,
|
||||
|
|
|
|||
Loading…
Reference in a new issue