[Django] #31843: PicklingError: Can't pickle <class 'django.db.models.query.Row'>: attribute lookup Row on django.db.models.query failed

46 views
Skip to first unread message

Django

unread,
Jul 31, 2020, 3:23:27 AM7/31/20
to django-...@googlegroups.com
#31843: PicklingError: Can't pickle <class 'django.db.models.query.Row'>: attribute
lookup Row on django.db.models.query failed
-------------------------------------+-------------------------------------
Reporter: Vitaliy | Owner: nobody
Yelnik |
Type: Bug | Status: new
Component: Database | Version: 3.0
layer (models, ORM) | Keywords: pickle namedtuple
Severity: Normal | values_list
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 31, 2020, 7:57:27 AM7/31/20
to django-...@googlegroups.com
#31843: django.db.models.query.Row is not pickleable.
-------------------------------------+-------------------------------------
Reporter: Vitaliy Yelnik | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 3.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: pickle namedtuple | Triage Stage: Accepted
values_list |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* 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>

Django

unread,
Aug 1, 2020, 4:10:18 PM8/1/20
to django-...@googlegroups.com
#31843: django.db.models.query.Row is not pickleable.
-------------------------------------+-------------------------------------
Reporter: Vitaliy Yelnik | Owner: nobody
Type: Bug | Status: new

Component: Database layer | Version: 3.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: pickle namedtuple | Triage Stage: Accepted
values_list |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Aug 31, 2020, 3:52:51 AM8/31/20
to django-...@googlegroups.com
#31843: django.db.models.query.Row is not pickleable.
-------------------------------------+-------------------------------------
Reporter: Vitaliy Yelnik | Owner: Vitaliy
| Yelnik
Type: Bug | Status: assigned
Component: Database layer | Version: 3.1

(models, ORM) |
Severity: Normal | Resolution:
Keywords: pickle namedtuple | Triage Stage: Ready for
values_list | checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Vitaliy Yelnik):

* 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>

Django

unread,
Aug 31, 2020, 4:18:36 AM8/31/20
to django-...@googlegroups.com
#31843: django.db.models.query.Row is not pickleable.
-------------------------------------+-------------------------------------
Reporter: Vitaliy Yelnik | Owner: Vitaliy
| Yelnik
Type: Bug | Status: assigned
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: pickle namedtuple | Triage Stage: Accepted
values_list |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* 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>

Django

unread,
Sep 4, 2020, 4:40:37 AM9/4/20
to django-...@googlegroups.com
#31843: django.db.models.query.Row is not pickleable.
-------------------------------------+-------------------------------------
Reporter: Vitaliy Yelnik | Owner: Vitaliy
| Yelnik
Type: Bug | Status: assigned
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: pickle namedtuple | Triage Stage: Accepted
values_list |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* cc: Sergey Fedoseev (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/31843#comment:5>

Django

unread,
Sep 16, 2020, 5:26:13 AM9/16/20
to django-...@googlegroups.com
#31843: django.db.models.query.Row is not pickleable.
-------------------------------------+-------------------------------------
Reporter: Vitaliy Yelnik | Owner: Vitaliy
| Yelnik
Type: Bug | Status: assigned
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: pickle namedtuple | Triage Stage: Accepted
values_list |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/31843#comment:6>

Django

unread,
Sep 16, 2020, 7:45:53 AM9/16/20
to django-...@googlegroups.com
#31843: django.db.models.query.Row is not pickleable.
-------------------------------------+-------------------------------------
Reporter: Vitaliy Yelnik | Owner: Vitaliy
| Yelnik
Type: Bug | Status: assigned
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: pickle namedtuple | Triage Stage: Ready for
values_list | checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* needs_better_patch: 1 => 0


* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/31843#comment:7>

Django

unread,
Sep 17, 2020, 1:59:39 AM9/17/20
to django-...@googlegroups.com
#31843: django.db.models.query.Row is not pickleable.
-------------------------------------+-------------------------------------
Reporter: Vitaliy Yelnik | Owner: Vitaliy
| Yelnik
Type: Bug | Status: closed

Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution: fixed

Keywords: pickle namedtuple | Triage Stage: Ready for
values_list | checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* 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>

Reply all
Reply to author
Forward
0 new messages