Negative Indexing on results fails
Bug #239767 reported by
Ed Page
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Storm |
New
|
Undecided
|
Unassigned |
Bug Description
Platform: Windows
Python: 2.5
Storm: 0.12
Say my Result object from a find has 2 results in it.
>>> results[0] is not results[1]
True
>>> results[-2] is not results[-1]
False
>>> results = [result for result in results]
>>> results[0] is not results[1]
True
>>> results[-2] is not results[-1]
True
Negative indexing is always returning me the same value when using the Result object.
To post a comment you must log in.
If we don't support negative indices, we should check for them and raise an exception if we see them.
I implemented negative indices for the storm.sqlobject compatibility layer, but you usually want to avoid them. In many cases, negative indexing will require an additional COUNT() query to be issued to work out what the index actually refers to.
If you are after items at the end of the result set, I'd recommend using order_by() to reverse the order of the set and then use positive indices.