If the timeout is independent of the query itself, you could write your
own database backend. Inherit all the basic stuff from an existing
backend and change the database connection stuff to send across the
timeout settings.
If the timeout needs to change based on the query context, you'll need
to use a custom QuerySet each time, since you need a custom Query object
(in the future -- say, Django 1.2 timeframes -- this should be easier,
since replacing the Query object used en-masse will become practical).
You need to replace the Query.execute() method.
Longer-term (since this is django-dev, the longer-term solution is the
only interesting one :-) ), it might be interesting to come up with an
API for setting things like this on a per-query basis. Would be worth
investigating what other database wrappers and servers can do in this
respect so that we have a suitably generic wrapper. Shouldn't be at all
intrusive on the fat part of the user-base curve (since they won't use
it and it will be a no-op) and will be useful at the far right-hand
side.
> When I tried to do the query in the django shell i found that django
> returns an empty queryset on timeout.
Django doesn't know anything at all about the timeout. It's the database
API warapper (postgresql_psycopg2) that is returning with no results.
Django is interpreting that as the normal "no results returned" case.
Regards,
Malcolm
No, then it won't make sense. You don't have access to anything like
"user-agent" at the database backend level. It's not tied to web
requests. You could tie it to a setting, but that's the level of
granularity you have.
[Okay, you could shove stuff in threadlocals and be very careful about
managing the value and pass things around that way. Debugging will be
something almost entirely unlike fun in some cases, I'd imagine.]
Regards,
Malcolm
The Plot thickens a bit with whats happening in the case of the eaten
up QueryCanceled Error. Basically,
somewhere in the list protocol, the QueryCancelledError thrown by
psycopg2 gets eaten up!
[snip details]
I'm delving into the iterator protocol used by django and why it calls
__len__ but perhaps someone more familiar with the workings of
query.py could point me in the right direction?