Fixed #31943 -- Fixed recreating QuerySet.values()/values_list() when using a pickled Query.

This commit is contained in:
Hasan Ramezani 2020-09-10 14:34:04 +02:00 committed by Mariusz Felisiak
parent 84609b3205
commit 5362e08624
3 changed files with 39 additions and 1 deletions

View file

@ -106,6 +106,20 @@ the query construction and is not part of the public API. However, it is safe
(and fully supported) to pickle and unpickle the attribute's contents as
described here.
.. admonition:: Restrictions on ``QuerySet.values_list()``
If you recreate :meth:`QuerySet.values_list` using the pickled ``query``
attribute, it will be converted to :meth:`QuerySet.values`::
>>> import pickle
>>> qs = Blog.objects.values_list('id', 'name')
>>> qs
<QuerySet [(1, 'Beatles Blog')]>
>>> reloaded_qs = Blog.objects.all()
>>> reloaded_qs.query = pickle.loads(pickle.dumps(qs.query))
>>> reloaded_qs
<QuerySet [{'id': 1, 'name': 'Beatles Blog'}]>
.. admonition:: You can't share pickles between versions
Pickles of ``QuerySets`` are only valid for the version of Django that