From 27b68bcadf1ab2e9f7fd223aed42db352ccdc62d Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Wed, 12 Mar 2025 11:05:50 +0000 Subject: Fixed #36234 -- Restored single_object argument to LogEntry.objects.log_actions(). Thank you Adam Johnson for the report and fix. Thank you Sarah Boyce for your spot on analysis. Regression in c09bceef68e5abb79accedd12dade16aa6577a09, which is partially reverted in this branch. Co-authored-by: Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> --- django/contrib/admin/models.py | 8 ++++++-- django/contrib/admin/options.py | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'django') diff --git a/django/contrib/admin/models.py b/django/contrib/admin/models.py index 453e65cf01..57122dac35 100644 --- a/django/contrib/admin/models.py +++ b/django/contrib/admin/models.py @@ -24,7 +24,9 @@ ACTION_FLAG_CHOICES = [ class LogEntryManager(models.Manager): use_in_migrations = True - def log_actions(self, user_id, queryset, action_flag, change_message=""): + def log_actions( + self, user_id, queryset, action_flag, change_message="", *, single_object=False + ): if isinstance(change_message, list): change_message = json.dumps(change_message) @@ -45,7 +47,9 @@ class LogEntryManager(models.Manager): if len(log_entry_list) == 1: instance = log_entry_list[0] instance.save() - return instance + if single_object: + return instance + return [instance] return self.model.objects.bulk_create(log_entry_list) diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index 090b12151a..3c2cf9d130 100644 --- a/django/contrib/admin/options.py +++ b/django/contrib/admin/options.py @@ -946,6 +946,7 @@ class ModelAdmin(BaseModelAdmin): queryset=[obj], action_flag=ADDITION, change_message=message, + single_object=True, ) def log_change(self, request, obj, message): @@ -961,6 +962,7 @@ class ModelAdmin(BaseModelAdmin): queryset=[obj], action_flag=CHANGE, change_message=message, + single_object=True, ) def log_deletions(self, request, queryset): -- cgit v1.3