Opened 18 years ago

Closed 18 years ago

Last modified 18 years ago

#2008 closed defect (fixed)

Negative offset in DB query set array-slicing fails silently

Reported by: olau@… Owned by: Adrian Holovaty
Component: Database layer (models, ORM) Version: dev
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Ordinary Python array-slicing allows negative offsets to indicate accessing items from the end of an array, e.g.

l = ["foo", "bar", "baz"]
l[-1] <- returns "baz"
l[-2] <- returns "bar"

The same apparently does not work for querysets if they are not evaluated. Instead it fails silently. I've looked up the reference for select statements in SQLite and MySQL without finding anything obvious to remedy the problem, other than to reverse the ordering if present. But at least Django should give an error and not fail silently.

I'm using the syntax to extract the first and the last item of a sequence to summarize a larger set of items.

Change History (1)

comment:1 by Adrian Holovaty, 18 years ago

Resolution: fixed
Status: newclosed

Fixed in [2992].

Note: See TracTickets for help on using tickets.
Back to Top