django.db.models.query.Row is not pickleable.
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.
Change History
(8)
Description: |
modified (diff)
|
Summary: |
PicklingError: Can't pickle <class 'django.db.models.query.Row'>: attribute lookup Row on django.db.models.query failed → django.db.models.query.Row is not pickleable.
|
Triage Stage: |
Unreviewed → Accepted
|
Has patch: |
set
|
Owner: |
changed from nobody to Vitaliy Yelnik
|
Status: |
new → assigned
|
Triage Stage: |
Accepted → Ready for checkin
|
Version: |
3.0 → 3.1
|
Triage Stage: |
Ready for checkin → Accepted
|
Cc: |
Sergey Fedoseev added
|
Patch needs improvement: |
set
|
Patch needs improvement: |
unset
|
Triage Stage: |
Accepted → Ready for checkin
|
Resolution: |
→ fixed
|
Status: |
assigned → closed
|
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 inquery
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.