views:

79

answers:

2

We've got some really strange extraneous DB hits happening in our project. Is there any way to monitor where the requests are coming from, possibly by line number? The SQL printing middleware helps, but we've looked everywhere those kinds of requests might be generated and can't find the source.

If the above isn't possible, any pointers on narrowing down the source would be greatly appreciated.

+4  A: 

To find the code executing queries, you can install django-debug-toolbar to figure out what commands are being executed and which tables they're operating on.

Once you've done that, try hooking into the appropriate Django signals for those models and using print and assert to narrow the code.

I'm sure there's a better way to do some of this (a python debugger?) but this is the first thing that comes to mind and probably what I would end up doing myself.

John Debs
+1 for the debug toolbar. It should give the full traceback of where each query is being done.
Daniel Roseman
Yes! django-debug-toolbar is exactly what I was looking for. Thanks so much!
CaptainThrowup
A: 

The Python Debugger (pdb) is also helpful if you get to the point where print and assert statements are cumbersome.

import pdb; pdb.set_trace()

istruble