[Django] #32450: "TypeError: cannot pickle" when applying | operator to a Q object

30 views
Skip to first unread message

Django

unread,
Feb 16, 2021, 2:44:59 AM2/16/21
to django-...@googlegroups.com
#32450: "TypeError: cannot pickle" when applying | operator to a Q object
-------------------------------------+-------------------------------------
Reporter: Daniel | Owner: nobody
Izquierdo |
Type: Bug | Status: new
Component: Database | Version: 3.1
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Using a reference to a non-pickleable type of object such as `dict_keys`
in a `Q` object makes the `|` operator fail:

{{{
>>> from django.db.models import Q
>>> Q(x__in={}.keys())
<Q: (AND: ('x__in', dict_keys([])))>
>>> Q() | Q(x__in={}.keys())
Traceback (most recent call last):
...
TypeError: cannot pickle 'dict_keys' object
}}}

Even though this particular example could be solved by doing `Q() |
Q(x__in={})` it still feels like doing using `.keys()` should work.

I can work on a patch if there's agreement that this should not crash.

--
Ticket URL: <https://code.djangoproject.com/ticket/32450>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 16, 2021, 2:45:51 AM2/16/21
to django-...@googlegroups.com
#32450: "TypeError: cannot pickle" when applying | operator to a Q object
-------------------------------------+-------------------------------------
Reporter: Daniel Izquierdo | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Daniel Izquierdo:

Old description:

> Using a reference to a non-pickleable type of object such as `dict_keys`
> in a `Q` object makes the `|` operator fail:
>
> {{{
> >>> from django.db.models import Q
> >>> Q(x__in={}.keys())
> <Q: (AND: ('x__in', dict_keys([])))>
> >>> Q() | Q(x__in={}.keys())
> Traceback (most recent call last):
> ...
> TypeError: cannot pickle 'dict_keys' object
> }}}
>
> Even though this particular example could be solved by doing `Q() |
> Q(x__in={})` it still feels like doing using `.keys()` should work.
>
> I can work on a patch if there's agreement that this should not crash.

New description:

Using a reference to a non-pickleable type of object such as `dict_keys`
in a `Q` object makes the `|` operator fail:

{{{
>>> from django.db.models import Q
>>> Q(x__in={}.keys())
<Q: (AND: ('x__in', dict_keys([])))>
>>> Q() | Q(x__in={}.keys())
Traceback (most recent call last):
...
TypeError: cannot pickle 'dict_keys' object
}}}

Even though this particular example could be solved by doing `Q() |

Q(x__in={})` it still feels like using `.keys()` should work.

I can work on a patch if there's agreement that this should not crash.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/32450#comment:1>

Django

unread,
Feb 16, 2021, 7:04:05 AM2/16/21
to django-...@googlegroups.com
#32450: "TypeError: cannot pickle" when applying | operator to a Q object
-------------------------------------+-------------------------------------
Reporter: Daniel Izquierdo | Owner: nobody
Type: Bug | Status: new

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

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

* cc: Tom Forbes (added)
* stage: Unreviewed => Accepted


Comment:

Thanks for this report.

Regression in bb0b6e526340e638522e093765e534df4e4393d2.

--
Ticket URL: <https://code.djangoproject.com/ticket/32450#comment:2>

Django

unread,
Feb 18, 2021, 9:34:49 AM2/18/21
to django-...@googlegroups.com
#32450: "TypeError: cannot pickle" when applying | operator to a Q object
-------------------------------------+-------------------------------------
Reporter: Daniel Izquierdo | Owner: nobody
Type: Bug | Status: new

Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

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

* has_patch: 0 => 1
* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/32450#comment:3>

Django

unread,
Feb 18, 2021, 4:18:07 PM2/18/21
to django-...@googlegroups.com
#32450: "TypeError: cannot pickle" when applying | operator to a Q object
-------------------------------------+-------------------------------------
Reporter: Daniel Izquierdo | Owner: nobody
Type: Bug | Status: closed

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

Keywords: | Triage Stage: Ready for
| 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: new => closed
* resolution: => fixed


Comment:

In [changeset:"466920f6d726eee90d5566e0a9948e92b33a122e" 466920f6]:
{{{
#!CommitTicketReference repository=""
revision="466920f6d726eee90d5566e0a9948e92b33a122e"
Fixed #32450 -- Fixed crash when ANDing/ORing an empty Q() with not
pickleable Q().

Regression in bb0b6e526340e638522e093765e534df4e4393d2.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32450#comment:4>

Django

unread,
Feb 18, 2021, 4:18:30 PM2/18/21
to django-...@googlegroups.com
#32450: "TypeError: cannot pickle" when applying | operator to a Q object
-------------------------------------+-------------------------------------
Reporter: Daniel Izquierdo | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

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

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"0e2979e95d0f68f28c92c84c14655e7510d4e789" 0e2979e9]:
{{{
#!CommitTicketReference repository=""
revision="0e2979e95d0f68f28c92c84c14655e7510d4e789"
[3.2.x] Fixed #32450 -- Fixed crash when ANDing/ORing an empty Q() with
not pickleable Q().

Regression in bb0b6e526340e638522e093765e534df4e4393d2.

Backport of 466920f6d726eee90d5566e0a9948e92b33a122e from master
}}}

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

Reply all
Reply to author
Forward
0 new messages