﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
34966	Add a check for ModelAdmin.actions functions not taking three arguments	Riccardo Magliocchetti	nobody	"Recently I've introduced a runtime exception because after a refactoring a function implementing an action got renamed but the old name stayed as an helper with 1 parameter. Setting in ModelAdmin.actions a function that does not take 3 arguments will raise an exception in BaseModelAdmin.response_action.
A check that will throw an error in that case could have saved me some embarassament in production :)

A rough untested implementation could look something like that:

{{{
diff --git a/django/contrib/admin/checks.py b/django/contrib/admin/checks.py
index 1665023434..9c4f7f125a 100644
--- a/django/contrib/admin/checks.py
+++ b/django/contrib/admin/checks.py
@@ -1,4 +1,5 @@
 import collections
+import inspect
 from itertools import chain
 
 from django.apps import apps
@@ -1244,6 +1245,31 @@ class ModelAdminChecks(BaseModelAdminChecks):
                 )
         return errors
 
+    def _check_actions_parameters(self, obj):
+        """"""Check that every action takes the correct number of parameters.""""""
+        errors = []
+        actions = obj._get_base_actions()
+        expected_func_parameters = 3
+        for func, name, _ in actions:
+            params = inspect.signature(func).parameters.values()
+            # TODO: does people define actions functions with more parameters with a default?
+            if len(params) != expected_func_parameters:
+                errors.append(
+                    checks.Error(
+                        ""action %r used in %s has an invalid number of parameters. Expected %d got %d.""
+                        % (
+                            name,
+                            obj.__class__.__name__,
+                            expected_func_parameters,
+                            len(params),
+                        ),
+                        obj=obj.__class__,
+                        id=""admin.E131"",
+                    )
+                )
+        return errors
+
+
 
 class InlineModelAdminChecks(BaseModelAdminChecks):
     def check(self, inline_obj, **kwargs):

}}}"	New feature	closed	contrib.admin	dev	Normal	wontfix	admin actions	Riccardo Magliocchetti	Unreviewed	0	0	0	0	0	0
