On 4 avr, 17:44, Adam Tonks <a...@adam-tonks.co.uk> wrote: > On Monday, April 4, 2011 4:34:10 PM UTC+1, bruno desthuilliers wrote: > > > If you really did test on the very same data set, same forum, *same > > thread* (IOW ; same value for "self.pk") etc, you would'nt get an > > IndexError, so there's obviously something different. > > I was literally just adding the [0] and refreshing the page, doing nothing > else differently. With the [0], it errors. Without the [0], I get a list > with two items.
This shouldn't happen, definitly. Getting at the first item of a non- empty queryset is something that should JustWork(tm), and it's very unlikely that such a major bug could make it's way into a stable release - FWIW, I've been using Django since the 0.96 days and I'd be very surprised to get such a problem even on the trunk. > The reason I posted this in here was for the very reason > that I was getting an IndexError on a set that almost certainly shouldn't be > empty. Making 100% sure your queryset is not empty when this error occurs is no big deal. If you manage to reproduce this behaviour with a proven non-empty queryset, then you can submit a bug report. > I also worked out that the set wasn't empty by accessing the first item from > the template instead (i.e. adding '.0' to the end of the value in the > template tag, instead of [0] to the end of the return function in the > model). > > > ... > > > This returns all posts, whatever thread they belongs to. > > I know, I was trying to point out that the change in behaviour when I add > the [0] is most likely due to the filter command. If you mean that adding the call to queryset.filter can result in an empty queryset, then yes, obviously you can't hope to subscript it. > > > It's not "causing it to return an empty queryset", it's raising an > > index error because your queryset is already empty. > > If you know of a better way I can test it, I'd appreciate it, it will come > in useful if something like this happens again. I posted some code about this. Also and FWIW, "./manage.py shell" let you run any arbitrary code against your models so you can try out and explore interactively. And there's of course the debugger. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.