Querysets aren't picklable. It's really hard! I'll work on it at some
point, but... it's really hard!
Turn them into a list instead and cache that.
Malcolm
--
Tolkien is hobbit-forming.
http://www.pointy-stick.com/blog/
To be more specific: I know what has to be done and have something
half-implemented. It's fairly deep internals stuff, though, so it
requires a bit more thinking and testing and is a little lower priority
than some other missing features.
Caching a list version of the queryset is almost certainly more
efficient (it requires you to turn the queryset into a list, which is a
small hassle): if we pickle a queryset, we're going to have to load all
the results from the database, so now you're pickling the results plus
all the queryset + query overhead. If you cache the list, you get rid of
that second chunk.
Regards,
Malcolm
--
Many are called, few volunteer.
http://www.pointy-stick.com/blog/
list(Country.objects.exclude(id=1).order_by('name') will be faster and
less code to write.
>
> Now, just out of curiosity, why didn't I get an error before using
> queryset refactor. I can't be sure that the caching actually happened,
> but there was no exception raised.
It's actually the Query class inside the QuerySet that is causing the
problem (partly because of the connection to the database backend, which
we have to not pickle); that contains a lot of stuff that didn't exist
before. There are also subtleties in the current implementation because
there's a lot more internal state to manage and once you unpickle a
queryset it's reasonable to expect you can still use it to further
filter the results, which means getting the internal state right on
unpickling.
Malcolm
--
Save the whales. Collect the whole set.
http://www.pointy-stick.com/blog/