#35395: slice filter crashes on an empty dict with Python 3.12
---------------------------------+------------------------------------
Reporter: Tim Richardson | Owner: nobody
Type: Bug | Status: new
Component: Template system | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by Tim Graham):
* easy: 0 => 1
* resolution: needsinfo =>
* stage: Unreviewed => Accepted
* status: closed => new
* summary: Python 3.12 filter bug with Django 4.2.11 => slice filter
crashes on an empty dict with Python 3.12
Comment:
Thanks. It looks like unexpected usage since slicing dictionaries doesn't
make sense. It won't hurt to fix it, but I don't think the fix will be
backported so you may have to work around it in your code.
A test which passes on Python 3.11 and crashes on 3.12.
{{{#!diff
diff --git a/tests/template_tests/filter_tests/test_slice.py
b/tests/template_tests/filter_tests/test_slice.py
index 5a5dd6b155..23257b1282 100644
--- a/tests/template_tests/filter_tests/test_slice.py
+++ b/tests/template_tests/filter_tests/test_slice.py
@@ -53,3 +53,6 @@ class FunctionTests(SimpleTestCase):
def test_fail_silently(self):
obj = object()
self.assertEqual(slice_filter(obj, "0::2"), obj)
+
+ def test_empty_dict(self):
+ self.assertEqual(slice_filter({}, "1"), {})
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35395#comment:5>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107018f061c4dec-5dd336ff-a078-4304-be3a-ae533b9e834d-000000%40eu-central-1.amazonses.com.