connection.queries show no queries

1,148 views
Skip to first unread message

Continuation

unread,
Nov 17, 2009, 7:15:42 PM11/17/09
to Django users
I'm running a django project (actually a Pinax project) on the
development server.

At my settings.py I made sure DEBUG = True

Then I hit a few pages that for sure resulted in hitting the database.

Then I did "python manage.py shell" to bring up the interactive
console.

Next I tried to look at the raw SQl queries that were generated by
Django:

In [2]: from django.db import connection
In [3]: connection.queries
Out[3]: []

Why is connection.queries empty? I tried this several times with the
same results.

What have i missed?

Karen Tracey

unread,
Nov 17, 2009, 7:41:24 PM11/17/09
to django...@googlegroups.com

You can't access the connection.queries for the running server process by starting up an independent shell.  The queries attribute is associated with a database connection -- the shell session you start makes its own connection to the database and will have its own independent connection.queries.  Thus when you look at connection.queries from the shell, you see the queries that have been issued from the shell process. 

(Also, in fact a new database connection is established and torn down for each request processed by the server, so even the running server is not maintaining a complete list of queries for the life of the server -- it just maintains a list for the life of a particular connection, which generally only lasts the lifetime of an individual request.)

If you want to see the queries needed to generate particular pages, probably the easiest way is to install django-debug-toolbar:

http://robhudson.github.com/django-debug-toolbar/

Karen


Jani Tiainen

unread,
Nov 18, 2009, 2:39:09 AM11/18/09
to django...@googlegroups.com
Probably you missed the fact that your webserver runs Django in totally
different processes than your shell. So you really can't expect that you
see any queries since you don't have executed any in your shell process.

Try debug toolbar for example to be able to see what actually happens
under the hood.

--

Jani Tiainen

Reply all
Reply to author
Forward
0 new messages