Thursday, June 24, 2010

Re: Manager's get_query_set are cached ?

On Jun 24, 6:36 pm, Xavier Ordoquy <xordo...@linovia.com> wrote:
> Hi,
>
> I'm banging my head against the wall with an issue in get_query_set.
>
> I'm using django 1.2.1 and I'd like to filter the queryset results through a date within get_query_set.
> However, I noticed that with the dev. server or gunicorn, the get_query_set is only called on the first request.
>
> This manager is called from a queryset passed to a generic function so unless those functions have builtin cache, I don't understand why the get_query_set is only called on the first request.
> Has anyone an idea why this happens ?

From your description, it sounds like you're doing something like
this:

def my_function(queryset=MyModel.objects.all())
return queryset.filter(whatever=whatever)

This is a standard Python gotcha, nothing to do with Django: never use
a mutable variable as a default parameter to a function. It is
executed *when the function is first defined*, not when it's called.
Use 'queryset=None' instead and set the default within the function.

If this isn't what you're doing, you need to show some actual code.
--
DR.

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate