#35395: Python 3.12 filter bug with Django 4.2.11
---------------------------------+--------------------------------------
     Reporter:  Tim Richardson   |                    Owner:  nobody
         Type:  Bug              |                   Status:  closed
    Component:  Template system  |                  Version:  4.2
     Severity:  Normal           |               Resolution:  needsinfo
     Keywords:                   |             Triage Stage:  Unreviewed
    Has patch:  0                |      Needs documentation:  0
  Needs tests:  0                |  Patch needs improvement:  0
Easy pickings:  0                |                    UI/UX:  0
---------------------------------+--------------------------------------
Comment (by Tim Richardson):

 Fair enough.

 The code below is the slice_filter from the 4.2.11 source.


 If you run this code in python 3.11,
 the filter returns
 {}

 (an empty dict)

 If you run it in python 3.12, it raises an exception.

 {{{
 Traceback (most recent call last):
   File "/app/./test_filter.py", line 21, in <module>
     r = slice_filter({},":5")
         ^^^^^^^^^^^^^^^^^^^^^
   File "/app/./test_filter.py", line 13, in slice_filter
     return value[slice(*bits)]
            ~~~~~^^^^^^^^^^^^^^
 }}}
 KeyError: slice(None, 5, None)



 {{{
 def slice_filter(value, arg):
     """
     Return a slice of the list using the same syntax as Python's list
 slicing.
     """
     try:
         bits = []
         for x in str(arg).split(":"):
             if not x:
                 bits.append(None)
             else:
                 bits.append(int(x))
         return value[slice(*bits)]
     except (ValueError, TypeError) as e:
         return value  # Fail silently.




 if __name__ == "__main__":
     r = slice_filter({},":5")
     print(f"{r=}")
 }}}


 I will try to work out why, but this at least describes the problem I
 think.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35395#comment:3>
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/0107018f05b269b7-e2c74100-d71d-45db-b937-25ca43f034b9-000000%40eu-central-1.amazonses.com.

Reply via email to