mirror of https://github.com/django/django.git
Fixed #35395 -- slice filter crashes on an empty dict with Python 3.12.
Keep consistent behaviour of slice() filter between python 3.12 and prior versions in the case of a dict passed to the filter (catch the new to python 3.12 KeyError exception).
This commit is contained in:
parent
16d0542bb6
commit
e64d42e753
|
@ -644,7 +644,7 @@ def slice_filter(value, arg):
|
|||
bits.append(int(x))
|
||||
return value[slice(*bits)]
|
||||
|
||||
except (ValueError, TypeError):
|
||||
except (ValueError, TypeError, KeyError):
|
||||
return value # Fail silently.
|
||||
|
||||
|
||||
|
|
|
@ -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"), {})
|
||||
|
|
Loading…
Reference in New Issue