#267 reslicing SelectResults object leads to error

closed-accepted
Oleg Broytman
None
5
2011-07-18
2011-07-18
mexicanferret
No

reslicing SelectResults object sometimes leads to error
Ex:
my_selection[0:10][0:20] will result in a "slice object is unsuscriptable" error

This is because of a typo in the sresults.py file line 156.

[code]if self.ops.get('end', None) is not None and value['end'] < end:[/code]

should be replaced by

[code]if self.ops.get('end', None) is not None and self.ops['end'] < end:[/code]

value is a slice object and is indeed unsuscriptable.

I attach the corrected file.

Discussion

  • mexicanferret
    mexicanferret
    2011-07-18

     
    Attachments
  • Oleg Broytman
    Oleg Broytman
    2011-07-18

    • assigned_to: nobody --> phd
    • status: open --> open-works-for-me
     
  • Oleg Broytman
    Oleg Broytman
    2011-07-18

    I cannot reproduce the problem. This program works:

    class Test(SQLObject):
    test = StringCol()

    Test.createTable()

    Test(test='1')
    Test(test='2')
    Test(test='3')
    Test(test='4')
    Test(test='5')

    print list(Test.select()[0:3][0:5])

    It prints

    [<Test 1 test='1'>, <Test 2 test='2'>, <Test 3 test='3'>]

    Looks good, right? I use SQLObject 1.1. What version do you have problems with?

     
  • mexicanferret
    mexicanferret
    2011-07-18

    OK it works when the slice starts with 0 but try this: my_selection[1:10][1:20]

    You will get:

    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "/usr/lib/python2.7/site-packages/sqlobject/sresults.py", line 156, in __getitem__
    and value['end'] < end:
    TypeError: 'slice' object is not subscriptable

     
  • Oleg Broytman
    Oleg Broytman
    2011-07-18

    Yes, you are right. Your fix is applied and committed in the revisions 4429:4431 (branches 1.0, 1.1 and the trunk). Will be in the next round of releases. Thank you!

     
  • Oleg Broytman
    Oleg Broytman
    2011-07-18

    • status: open-works-for-me --> closed-accepted