Re: Queryset unexpectedly turning into list
> "Normally" (which might well mean "hopefully") it shouldn't matter > whether you're getting back an iterator or a list (which is still > iterable) at that point in the code. I could imagine or construct code > that behaves differently in the two cases, but do you have a real-life > case where the change in type is causing a problem? After being remembered that placing code before/after evaluation is the point of the matter it was quite easy to fix. Here is what I was trying to do: http://dpaste.com/114134/ The queryset is used to populate a form and a subset of the field is needed at a other place in the template. My intention was to: a) find the first 20 results b) know if result amount exceeds the limit I guess there's much room for optimizations ;) --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Queryset unexpectedly turning into list
On Sat, 2009-01-24 at 19:57 -0800, mb0...@googlemail.com wrote: > Ah, ok thanks for the explanation :) Alex's explanation is correct (as his explanations tend to be). I just wanted to add some extra thoughts to that... "Normally" (which might well mean "hopefully") it shouldn't matter whether you're getting back an iterator or a list (which is still iterable) at that point in the code. I could imagine or construct code that behaves differently in the two cases, but do you have a real-life case where the change in type is causing a problem? Slicing on querysets, particularly as it interacts with caching and with all the different things that people try to do, is one of the really hard areas to get right. In fact, it's one of the few areas of the ORM where there are still known behavioural bugs, although fortunately it's not something that will affect many people (and to be fixed before Django 1.1 and 1.0.3 come out, with luck). So whilst not every wish can be granted in this area, even all reasonable wishes, it would be interesting to know whether this is causing unreasonable levels of difficulty somewhere. Regards, Malcolm --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Queryset unexpectedly turning into list
Ah, ok thanks for the explanation :) --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Queryset unexpectedly turning into list
All magic happens in line: if(queryset):#check if query returned somethin To perform this check QuerySet is evaluated and makes query to DB and stores result in list. After that QuerySet slice operation make real slice on underlying cache and of cource return list. On Sun, Jan 25, 2009 at 1:26 AM, mb0...@googlemail.com < mb0...@googlemail.com> wrote: > > Hi, > > please have a look at: http://dpaste.com/112603/ > > Can someone tell me why the sliced queryset suddenly turns into a > list? > I'm still new to Python/Django so I can't tell if it is a bug... but > it sure cost me some time because in my eyes it was something complete > out of the blue. > > Django version 1.0.2 > Python 2.5.2 > > Kind regards, > Martin > > > --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Queryset unexpectedly turning into list
On Sat, Jan 24, 2009 at 8:26 PM, mb0...@googlemail.com wrote: > > Hi, > > please have a look at: http://dpaste.com/112603/ > > Can someone tell me why the sliced queryset suddenly turns into a > list? > I'm still new to Python/Django so I can't tell if it is a bug... but > it sure cost me some time because in my eyes it was something complete > out of the blue. > > Django version 1.0.2 > Python 2.5.2 > What DB backend are you using?. -- Ramiro Morales --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Queryset unexpectedly turning into list
Hi, please have a look at: http://dpaste.com/112603/ Can someone tell me why the sliced queryset suddenly turns into a list? I'm still new to Python/Django so I can't tell if it is a bug... but it sure cost me some time because in my eyes it was something complete out of the blue. Django version 1.0.2 Python 2.5.2 Kind regards, Martin --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---