Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#32450 closed Bug (fixed)

"TypeError: cannot pickle" when applying | operator to a Q object

Reported by: Daniel Izquierdo Owned by: nobody
Component: Database layer (models, ORM) Version: 3.1
Severity: Normal Keywords:
Cc: Tom Forbes Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Daniel Izquierdo)

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.

Change History (5)

comment:1 by Daniel Izquierdo, 4 years ago

Description: modified (diff)

comment:2 by Mariusz Felisiak, 4 years ago

Cc: Tom Forbes added
Triage Stage: UnreviewedAccepted

Thanks for this report.

Regression in bb0b6e526340e638522e093765e534df4e4393d2.

comment:3 by Simon Charette, 4 years ago

Has patch: set
Triage Stage: AcceptedReady for checkin

comment:4 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

Resolution: fixed
Status: newclosed

In 466920f6:

Fixed #32450 -- Fixed crash when ANDing/ORing an empty Q() with not pickleable Q().

Regression in bb0b6e526340e638522e093765e534df4e4393d2.

comment:5 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

In 0e2979e9:

[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

Note: See TracTickets for help on using tickets.
Back to Top