mirror of
https://github.com/django/django.git
synced 2025-03-12 18:30:48 +00:00
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))
|
bits.append(int(x))
|
||||||
return value[slice(*bits)]
|
return value[slice(*bits)]
|
||||||
|
|
||||||
except (ValueError, TypeError):
|
except (ValueError, TypeError, KeyError):
|
||||||
return value # Fail silently.
|
return value # Fail silently.
|
||||||
|
|
||||||
|
|
||||||
|
@ -53,3 +53,6 @@ class FunctionTests(SimpleTestCase):
|
|||||||
def test_fail_silently(self):
|
def test_fail_silently(self):
|
||||||
obj = object()
|
obj = object()
|
||||||
self.assertEqual(slice_filter(obj, "0::2"), obj)
|
self.assertEqual(slice_filter(obj, "0::2"), obj)
|
||||||
|
|
||||||
|
def test_empty_dict(self):
|
||||||
|
self.assertEqual(slice_filter({}, "1"), {})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user