How to debug ORM filter stacking?

2010-09-24 Thread ydjango
I am stacking filters on queryset. For some reason the second filter
in stack is not applying and it is not giving any error either. Any
way to debug what is going on?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: How to debug ORM filter stacking?

2010-09-25 Thread bagheera

Dnia 25-09-2010 o 06:17:10 ydjango  napisaƂ(a):


I am stacking filters on queryset. For some reason the second filter
in stack is not applying and it is not giving any error either. Any
way to debug what is going on?


python manage.py shell

Import ur model, and build ur queries live. ipython has neat autoompletion  
feature. You might be able to figure out why it is working like it is.


--
Linux user

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-us...@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: How to debug ORM filter stacking?

2010-09-25 Thread Ian Lewis
Are you sure you are saving the new QuerySet that gets created by the
filter? I'm guessing you are doing something like:

qs = MyModel.objects.filter(field1="somevalue")
if condition:
qs.filter("someothervalue")

What you need to do is save the value of the second filter() call.

qs = MyModel.objects.filter(field1="somevalue")
if condition:
qs = qs.filter("someothervalue")

filter() returns a new queryset object rather than modifying the
queryset in place.

I usually debug SQL problems by using the
http://github.com/robhudson/django-debug-toolbar or pdb. With pdb you
can put import pdb;pdb.set_trace() where you would like pdb to stop
and it will allow you to debug from there. Simply showing the results
of the queryset usually gives some clues as to what the problem is. In
pdb you can see what sql will get run by running

(Pdb) print queryset.query

pdb's commands are explained here:

http://docs.python.org/library/pdb.html#debugger-commands


On Sat, Sep 25, 2010 at 1:17 PM, ydjango  wrote:
> I am stacking filters on queryset. For some reason the second filter
> in stack is not applying and it is not giving any error either. Any
> way to debug what is going on?
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@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.
>
>


-- 
Ian

http://www.ianlewis.org/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.