summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Walls <jacobtylerwalls@gmail.com>2026-06-10 16:24:10 -0400
committerJacob Walls <jacobtylerwalls@gmail.com>2026-06-10 17:15:59 -0400
commita2f8a4a6f9ac094edde937e56a3ecbd112ee448c (patch)
tree4423af3d5fb9382140692fac01cfdfc52c88682b
parent15bcbeeb95ca34385c119acea14df1f5e7274d45 (diff)
Fixed #36104 -- Returned NotImplemented in Media.__add__ for non-Media RHS.
-rw-r--r--django/forms/widgets.py2
-rw-r--r--tests/forms_tests/tests/test_media.py7
2 files changed, 9 insertions, 0 deletions
diff --git a/django/forms/widgets.py b/django/forms/widgets.py
index 56ff7bb5ad..82498aa662 100644
--- a/django/forms/widgets.py
+++ b/django/forms/widgets.py
@@ -262,6 +262,8 @@ class Media:
return list(dict.fromkeys(chain.from_iterable(filter(None, lists))))
def __add__(self, other):
+ if not isinstance(other, Media):
+ return NotImplemented
combined = Media()
combined._css_lists = self._css_lists[:]
combined._js_lists = self._js_lists[:]
diff --git a/tests/forms_tests/tests/test_media.py b/tests/forms_tests/tests/test_media.py
index b24ed948a9..854e52d95c 100644
--- a/tests/forms_tests/tests/test_media.py
+++ b/tests/forms_tests/tests/test_media.py
@@ -859,6 +859,13 @@ class FormsMediaTestCase(SimpleTestCase):
self.assertEqual(merged._css_lists, [{"screen": ["a.css"]}])
self.assertEqual(merged._js_lists, [["a"]])
+ def test_add_invalid_type(self):
+ class InvalidType:
+ pass
+
+ with self.assertRaises(TypeError):
+ Media() + InvalidType()
+
def test_render_js_with_attrs(self):
media = Media(js=[Script("/path/to/js", integrity="sha256-abc")])
self.assertHTMLEqual(