Re: [Django] #13089: Support Negative Indexing on QuerySets

19 views
Skip to first unread message

Django

unread,
Dec 5, 2012, 3:31:54 AM12/5/12
to django-...@googlegroups.com
#13089: Support Negative Indexing on QuerySets
-------------------------------------+-------------------------------------
Reporter: adamnelson | Owner: nobody
Type: Uncategorized | Status: closed
Component: Database layer | Version: master
(models, ORM) | Resolution: wontfix
Severity: Normal | Triage Stage:
Keywords: feature | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by a.mamish@…):

* ui_ux: => 0
* type: => Uncategorized
* severity: => Normal
* easy: => 0


Comment:

I think this is more important than many think. It's a Python idiom that
gets lost in translation. You are emulating lists with the sets and their
indexing, it's only natural to support negative indexing as the language
does. It surprised me when I started using Django that this didn't work,
and I was so happy to be able to do that with Python while typing it too!

--
Ticket URL: <https://code.djangoproject.com/ticket/13089#comment:5>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 26, 2013, 4:52:49 PM3/26/13
to django-...@googlegroups.com
#13089: Support Negative Indexing on QuerySets
-------------------------------------+-------------------------------------
Reporter: adamnelson | Owner: nobody
Type: Uncategorized | Status: closed
Component: Database layer | Version: master
(models, ORM) | Resolution: wontfix
Severity: Normal | Triage Stage:
Keywords: feature | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by anonymous):

bump

--
Ticket URL: <https://code.djangoproject.com/ticket/13089#comment:6>

Django

unread,
Jul 14, 2013, 3:54:05 PM7/14/13
to django-...@googlegroups.com
#13089: Support Negative Indexing on QuerySets
-------------------------------------+-------------------------------------
Reporter: adamnelson | Owner: nobody
Type: Uncategorized | Status: closed
Component: Database layer | Version: master
(models, ORM) | Resolution: wontfix
Severity: Normal | Triage Stage:
Keywords: feature | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by anonymous):

Is there any justification for the design decision? I don't really see how
halfway supporting indexing (unless there's some good DB-related reason
for it) is good design.

--
Ticket URL: <https://code.djangoproject.com/ticket/13089#comment:7>

Django

unread,
Jul 15, 2013, 5:33:20 AM7/15/13
to django-...@googlegroups.com
#13089: Support Negative Indexing on QuerySets
-------------------------------------+-------------------------------------
Reporter: adamnelson | Owner: nobody
Type: Uncategorized | Status: closed
Component: Database layer | Version: master
(models, ORM) | Resolution: wontfix
Severity: Normal | Triage Stage:
Keywords: feature | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by loic84):

FWIW I'm +1 on this.

I don't like when we stop halfway when emulating a python idiom; either we
use our own unrelated API or we comply with the basic expectations that
come with the idiom.

In any case, if you care about this, you need to post to the ML; closed
tickets receive very little attention so they aren't a good place to
debate this kind of decisions.

--
Ticket URL: <https://code.djangoproject.com/ticket/13089#comment:8>

Django

unread,
Jul 30, 2013, 6:48:37 PM7/30/13
to django-...@googlegroups.com
#13089: Support Negative Indexing on QuerySets
-------------------------------------+-------------------------------------
Reporter: adamnelson | Owner: nobody
Type: Uncategorized | Status: closed
Component: Database layer | Version: master
(models, ORM) | Resolution: wontfix
Severity: Normal | Triage Stage:
Keywords: feature | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by django@…):

Replying to [comment:8 loic84]:


> FWIW I'm +1 on this.
>
> I don't like when we stop halfway when emulating a python idiom; either
we use our own unrelated API or we comply with the basic expectations that
come with the idiom.
>

In short: querysets are not == lists.

The problem with saying the python negative indexing idiom should be
supported is that negative indexing applies nicely to sets, lists, dicts
etc where you know the length of the set, list, dict etc.

AFAIK, you can't negative index a generator without first exhausting the
generator ... that would be a similar (but not identical) analogy to
negative indexing a queryset (ie you have to retrieve the whole queryset
before you can know the size).
I realise that the ORM could invert the sort and then re-write the slice
for you.

--
Ticket URL: <https://code.djangoproject.com/ticket/13089#comment:9>

Django

unread,
Jul 31, 2013, 5:11:26 AM7/31/13
to django-...@googlegroups.com
#13089: Support Negative Indexing on QuerySets
-------------------------------------+-------------------------------------
Reporter: adamnelson | Owner: nobody
Type: Uncategorized | Status: closed
Component: Database layer | Version: master
(models, ORM) | Resolution: wontfix
Severity: Normal | Triage Stage:
Keywords: feature | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by loic84):

Replying to [comment:9 django@…]:


> AFAIK, you can't negative index a generator without first exhausting the
generator ... that would be a similar (but not identical) analogy to
negative indexing a queryset (ie you have to retrieve the whole queryset
before you can know the size).

Negative indexing could be implemented without performance issues, just
look at the implementation of `QuerySet.__getitem__()`.

The fancy slicing operations like `[::2]` which don't translate well to
SQL are the real problem, I don't think we need to support those.

--
Ticket URL: <https://code.djangoproject.com/ticket/13089#comment:10>

Django

unread,
Jul 31, 2013, 2:46:49 PM7/31/13
to django-...@googlegroups.com
#13089: Support Negative Indexing on QuerySets
-------------------------------------+-------------------------------------
Reporter: adamnelson | Owner: nobody
Type: Uncategorized | Status: closed
Component: Database layer | Version: master
(models, ORM) | Resolution: wontfix
Severity: Normal | Triage Stage:
Keywords: feature | Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by loic84):

* cc: loic@… (added)
* has_patch: 0 => 1


Comment:

POC https://github.com/loic/django/compare/ticket13089

--
Ticket URL: <https://code.djangoproject.com/ticket/13089#comment:11>

Django

unread,
Mar 28, 2014, 9:31:34 AM3/28/14
to django-...@googlegroups.com
#13089: Support Negative Indexing on QuerySets
-------------------------------------+-------------------------------------
Reporter: adamnelson | Owner: nobody
Type: Uncategorized | Status: closed
Component: Database layer | Version: master
(models, ORM) | Resolution: wontfix
Severity: Normal | Triage Stage:
Keywords: feature | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by anonymous):

+1
violates principle of least surprise

--
Ticket URL: <https://code.djangoproject.com/ticket/13089#comment:12>

Django

unread,
Feb 5, 2015, 7:34:56 PM2/5/15
to django-...@googlegroups.com
#13089: Support Negative Indexing on QuerySets
-------------------------------------+-------------------------------------
Reporter: adamnelson | Owner: nobody
Type: Uncategorized | Status: closed
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: wontfix
Keywords: feature | Triage Stage:

| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by yscumc):

+1
I was surprised by this and had to use `qs[len(qs)-1]` as a workaround.

--
Ticket URL: <https://code.djangoproject.com/ticket/13089#comment:13>

Django

unread,
Dec 8, 2016, 4:07:16 AM12/8/16
to django-...@googlegroups.com
#13089: Support Negative Indexing on QuerySets
-------------------------------------+-------------------------------------
Reporter: Adam Nelson | Owner: nobody

Type: Uncategorized | Status: closed
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: wontfix
Keywords: feature | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Florian Verdet):

It's even more surprising for {{{values_list()}}} -- especially for
{{{values_list( 'field', flat=True)}}}, since it has {{{list}}} in its
name...

--
Ticket URL: <https://code.djangoproject.com/ticket/13089#comment:14>

Django

unread,
Oct 4, 2018, 3:55:53 AM10/4/18
to django-...@googlegroups.com
#13089: Support Negative Indexing on QuerySets
-------------------------------------+-------------------------------------
Reporter: Adam Nelson | Owner: nobody
Type: Uncategorized | Status: closed
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: wontfix
Keywords: feature | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Daniel Hahler):

Just for reference: it was discussed on the mailing list at
https://groups.google.com/d/msg/django-
developers/x86iWFnZiik/wyeI5woWkVYJ.

--
Ticket URL: <https://code.djangoproject.com/ticket/13089#comment:15>

Reply all
Reply to author
Forward
0 new messages