collection[-1] raises an error : *** ValueError: Collection slices must have a nonnegative start point.

Bug #583761 reported by Robert Collins on 2010-05-21
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
lazr.restfulclient
Low
Unassigned

Bug Description

It would be nice, for a collection, to be able to do [-1] to get the last element, like [0] gets the first. The following is a distillation of a chat Leonard and I had about this.

Leonard says: this could be done on server or client and while tricky there is no desire to avoid it per se.

a collection is a series of pages (in the vm sense) with a forward pointer called the next_link.

In small collections its one page and next is NULL.

One approach: client side only: ask for the root of the collection, we get a page + size of collection in items. Then we can make a request for -1 by taking size-1 and asking for collection?ws.start=$size_minus_one

If we change the server, requestion ws.start=-1 could do something other than blow up (as it does? probably does? today). One possibility is to translate the -1 to 'start at the end of the list'. Another is to start at the end of the list *and* invert the direction of additional data included. That is: 0 gives item 0 and page_count -1 additional items with monotonically increasing indices. -1 would give item -1 and page_count -1 additional items with monotonically decreasing indices.

Gary Poster (gary) wrote :

I'm +1 on this being done eventually. It should be considered for inclusion in the upcoming effort to make working with lazr.restful operations more "natural".

Changed in lazr.restfulclient:
status: New → Triaged
importance: Undecided → Low
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers