{{{
In [12]: row = ModelA.objects.values_list('id', 'value',
named=True).first()
In [14]: type(row)
Out[14]: django.db.models.query.Row
In [16]: pickle.dumps(row)
PicklingError: Can't pickle <class 'django.db.models.query.Row'>:
attribute lookup Row on django.db.models.query failed
}}}
In particular, as a result, such requests do not work with cacheops
package.
--
Ticket URL: <https://code.djangoproject.com/ticket/31843>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* stage: Unreviewed => Accepted
Old description:
> The new named parameter of QuerySet.values_list() was released In Django
> 2.0 (#15648).
> But resulted namedtuple-s can't be pickled:
> {{{
> class ModelA(models.Model):
> value = models.CharField(max_length=12)
> }}}
>
> {{{
> In [12]: row = ModelA.objects.values_list('id', 'value',
> named=True).first()
>
> In [14]: type(row)
> Out[14]: django.db.models.query.Row
>
> In [16]: pickle.dumps(row)
> PicklingError: Can't pickle <class 'django.db.models.query.Row'>:
> attribute lookup Row on django.db.models.query failed
> }}}
>
> In particular, as a result, such requests do not work with cacheops
> package.
New description:
The new named parameter of QuerySet.values_list() was released In Django
2.0 (#15648).
But resulted namedtuple-s can't be pickled:
{{{
class ModelA(models.Model):
value = models.CharField(max_length=12)
}}}
{{{
In [12]: row = ModelA.objects.values_list('id', 'value',
named=True).first()
In [14]: type(row)
Out[14]: django.db.models.query.Row
In [16]: pickle.dumps(row)
PicklingError: Can't pickle <class 'django.db.models.query.Row'>:
attribute lookup Row on django.db.models.query failed
}}}
In particular, as a result, such requests do not work with cacheops
package.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/31843#comment:1>
Comment (by Davit Tovmasyan):
In addition to the data contained in the instances, pickle also stores a
string reference to the original class. This means that `Row` tuple class
should be in `query` module globals so pickle can find the reference. But
besides that, it should have different class names for each model and for
each list of values.
--
Ticket URL: <https://code.djangoproject.com/ticket/31843#comment:2>
* owner: nobody => Vitaliy Yelnik
* status: new => assigned
* has_patch: 0 => 1
* version: 3.0 => 3.1
* stage: Accepted => Ready for checkin
Comment:
[[https://github.com/django/django/pull/13370|PR]]
--
Ticket URL: <https://code.djangoproject.com/ticket/31843#comment:3>
* stage: Ready for checkin => Accepted
Comment:
You shouldn't mark your own PRs as ready for checkin.
--
Ticket URL: <https://code.djangoproject.com/ticket/31843#comment:4>
* cc: Sergey Fedoseev (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/31843#comment:5>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/31843#comment:6>
* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/31843#comment:7>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"981a072dd4dec586f8fc606712ed9a2ef116eeee" 981a072d]:
{{{
#!CommitTicketReference repository=""
revision="981a072dd4dec586f8fc606712ed9a2ef116eeee"
Fixed #31843 -- Fixed pickling named values from QuerySet.values_list().
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/31843#comment:8>