Compare commits

...

5 commits

Author SHA1 Message Date
Tosinibikunle
9915f522d3
Merge aca5370b76 into 0e3a2ec1a7 2026-03-13 04:41:05 +00:00
pre-commit-ci[bot]
0e3a2ec1a7
[pre-commit.ci] pre-commit autoupdate (#808)
Some checks failed
Test / SQLite • Python 3.10 (push) Has been cancelled
Test / SQLite • Python 3.11 (push) Has been cancelled
Test / SQLite • Python 3.12 (push) Has been cancelled
Test / SQLite • Python 3.13 (push) Has been cancelled
Test / PostgreSQL • Python 3.10 (push) Has been cancelled
Test / PostgreSQL • Python 3.11 (push) Has been cancelled
Test / PostgreSQL • Python 3.12 (push) Has been cancelled
Test / PostgreSQL • Python 3.13 (push) Has been cancelled
Test / MySQL • Python 3.10 (push) Has been cancelled
Test / MySQL • Python 3.11 (push) Has been cancelled
Test / MySQL • Python 3.12 (push) Has been cancelled
Test / MySQL • Python 3.13 (push) Has been cancelled
updates:
- [github.com/psf/black-pre-commit-mirror: 26.1.0 → 26.3.0](https://github.com/psf/black-pre-commit-mirror/compare/26.1.0...26.3.0)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2026-03-10 10:58:29 +01:00
pre-commit-ci[bot]
dfd5b79d2d
[pre-commit.ci] pre-commit autoupdate (#807)
Some checks failed
Test / SQLite • Python 3.10 (push) Has been cancelled
Test / SQLite • Python 3.11 (push) Has been cancelled
Test / SQLite • Python 3.12 (push) Has been cancelled
Test / SQLite • Python 3.13 (push) Has been cancelled
Test / PostgreSQL • Python 3.10 (push) Has been cancelled
Test / PostgreSQL • Python 3.11 (push) Has been cancelled
Test / PostgreSQL • Python 3.12 (push) Has been cancelled
Test / PostgreSQL • Python 3.13 (push) Has been cancelled
Test / MySQL • Python 3.10 (push) Has been cancelled
Test / MySQL • Python 3.11 (push) Has been cancelled
Test / MySQL • Python 3.12 (push) Has been cancelled
Test / MySQL • Python 3.13 (push) Has been cancelled
updates:
- [github.com/PyCQA/isort: 8.0.0 → 8.0.1](https://github.com/PyCQA/isort/compare/8.0.0...8.0.1)
- [github.com/adamchainz/django-upgrade: 1.29.1 → 1.30.0](https://github.com/adamchainz/django-upgrade/compare/1.29.1...1.30.0)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2026-03-04 13:06:54 +01:00
pre-commit-ci[bot]
aca5370b76 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2025-08-20 14:58:43 +00:00
Tosinibikunle
99847e5d40 fix: defer field deletion error in auditlog 2025-08-20 15:53:04 +01:00
3 changed files with 38 additions and 3 deletions

View file

@ -1,7 +1,7 @@
---
repos:
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 26.1.0
rev: 26.3.0
hooks:
- id: black
language_version: python3.10
@ -14,7 +14,7 @@ repos:
- id: flake8
args: ["--max-line-length", "110"]
- repo: https://github.com/PyCQA/isort
rev: 8.0.0
rev: 8.0.1
hooks:
- id: isort
- repo: https://github.com/asottile/pyupgrade
@ -23,7 +23,7 @@ repos:
- id: pyupgrade
args: [--py310-plus]
- repo: https://github.com/adamchainz/django-upgrade
rev: 1.29.1
rev: 1.30.0
hooks:
- id: django-upgrade
args: [--target-version, "4.2"]

View file

@ -242,7 +242,21 @@ class LogEntryManager(models.Manager):
"fields", self._get_applicable_model_fields(instance, model_fields)
)
# safeguard: if fields explicitly set → only use them
if "fields" in kwargs:
allowed_fields = set(kwargs["fields"])
else:
allowed_fields = {f.name for f in instance._meta.fields}
instance_copy = self._get_copy_with_python_typed_fields(instance)
# drop any deferred field not in allowed_fields
for f in instance_copy._meta.fields:
if f.name not in allowed_fields and f.name in getattr(
instance_copy, "deferred_fields", []
):
setattr(instance_copy, f.name, None)
data = dict(
json.loads(serializers.serialize("json", (instance_copy,), **kwargs))[0]
)

View file

@ -24,6 +24,7 @@ from django.db.models import JSONField, Value
from django.db.models.functions import Now
from django.db.models.signals import pre_save
from django.test import RequestFactory, TestCase, TransactionTestCase, override_settings
from django.test.utils import isolate_apps
from django.urls import resolve, reverse
from django.utils import dateformat, formats
from django.utils import timezone as django_timezone
@ -137,6 +138,26 @@ class SimpleModelTest(TestCase):
msg="Changes string is correct",
)
@isolate_apps("auditlog_tests")
def test_deletion_with_deferred_fields_does_not_crash(db):
from auditlog.models import LogEntry
from auditlog.registry import auditlog
class Book(models.Model):
title = models.CharField(max_length=100)
description = models.TextField()
class Meta:
app_label = "auditlog_tests"
auditlog.register(Book, serialize_data=True)
b = Book.objects.create(title="foo", description="bar")
b = Book.objects.defer("description").get(id=b.id) # defer a field
b.delete()
assert LogEntry.objects.filter(object_pk=b.pk).exists()
def test_update_specific_field_supplied_via_save_method(self):
obj = self.obj