瀏覽代碼

Fixed #11715 -- Changed default value of ModelAdmin.actions/inlines to empty tuples.

This clarifies the intended pattern of overwriting the default value
rather than mutating it.
Jacob Walls 3 年之前
父節點
當前提交
dc9deea8e8
共有 3 個文件被更改,包括 11 次插入2 次删除
  1. 2 2
      django/contrib/admin/options.py
  2. 4 0
      docs/releases/4.1.txt
  3. 5 0
      tests/modeladmin/tests.py

+ 2 - 2
django/contrib/admin/options.py

@@ -565,7 +565,7 @@ class ModelAdmin(BaseModelAdmin):
     save_on_top = False
     paginator = Paginator
     preserve_filters = True
-    inlines = []
+    inlines = ()
 
     # Custom templates (designed to be over-ridden in subclasses)
     add_form_template = None
@@ -577,7 +577,7 @@ class ModelAdmin(BaseModelAdmin):
     popup_response_template = None
 
     # Actions
-    actions = []
+    actions = ()
     action_form = helpers.ActionForm
     actions_on_top = True
     actions_on_bottom = False

+ 4 - 0
docs/releases/4.1.txt

@@ -341,6 +341,10 @@ Miscellaneous
   ``request.META['CSRF_COOKIE']`` for storing the unmasked CSRF secret rather
   than a masked version. This is an undocumented, private API.
 
+* The :attr:`.ModelAdmin.actions` and
+  :attr:`~django.contrib.admin.ModelAdmin.inlines` attributes now default to an
+  empty tuple rather than an empty list to discourage unintended mutation.
+
 .. _deprecated-features-4.1:
 
 Features deprecated in 4.1

+ 5 - 0
tests/modeladmin/tests.py

@@ -50,6 +50,11 @@ class ModelAdminTests(TestCase):
         ma = ModelAdmin(Band, self.site)
         self.assertEqual(str(ma), 'modeladmin.ModelAdmin')
 
+    def test_default_attributes(self):
+        ma = ModelAdmin(Band, self.site)
+        self.assertEqual(ma.actions, ())
+        self.assertEqual(ma.inlines, ())
+
     # form/fields/fieldsets interaction ##############################
 
     def test_default_fields(self):