[Django] #36033: Getting TypeError: cannot pickle 'dict_values' object Error with Django 4.2.16

21 views
Skip to first unread message

Django

unread,
Dec 21, 2024, 12:22:25 PM12/21/24
to django-...@googlegroups.com
#36033: Getting TypeError: cannot pickle 'dict_values' object Error with Django
4.2.16
-------------------------------------+-------------------------------------
Reporter: Bittu Ray | Type:
| Uncategorized
Status: new | Component: Core
| (Cache system)
Version: 4.2 | Severity: Release
| blocker
Keywords: Django 4.2, Cache | Triage Stage:
error, Redis Cache, Pickle | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
I am using django-redis-cache 3.0.1 with Django 4.2.16, and I am getting
this error in one of admin page -
{{{
TypeError: cannot pickle 'dict_values' object
}}}

This same code is working when I use it with Django 3.2.25. The value for
which I am getting this error is


{{{
{
cls: <class 'django_select2.forms.ModelSelect2Widget'>,
max_results: 25,

queryset: [
<RecordQuerySet from business.models at 0xf8b2af2c1b50>,
<django.db.models.sql.query.Query object at 0xf8b2b7ed4940>
],

search_fields: [
"id__icontains",
[Filtered],
"telecom_operator__icontains",
"area_code__icontains",
"cloud_telephony_operator__icontains"
],
url: "/select2/fields/auto.json"
}
}}}


It's failing during Pickle serialization of the above value.
--
Ticket URL: <https://code.djangoproject.com/ticket/36033>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 21, 2024, 1:51:42 PM12/21/24
to django-...@googlegroups.com
#36033: Getting TypeError: cannot pickle 'dict_values' object Error with Django
4.2.16
-------------------------------------+-------------------------------------
Reporter: Bittu Ray | Owner: (none)
Type: Uncategorized | Status: closed
Component: Core (Cache system) | Version: 4.2
Severity: Normal | Resolution: invalid
Keywords: Django 4.2, Cache | Triage Stage:
error, Redis Cache, Pickle | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* resolution: => invalid
* severity: Release blocker => Normal
* status: new => closed

Comment:

Hello, thanks for the report, however, you haven't provided enough
information to reproduce the problem and demonstrate that this is a bug in
Django itself. django-redis-cache is a third-praty library. If you need
help debugging the issue to figure out where the problem lies, see
TicketClosingReasons/UseSupportChannels.
--
Ticket URL: <https://code.djangoproject.com/ticket/36033#comment:1>

Django

unread,
Dec 22, 2024, 12:03:02 AM12/22/24
to django-...@googlegroups.com
#36033: Getting TypeError: cannot pickle 'dict_values' object Error with Django
4.2.16
-------------------------------------+-------------------------------------
Reporter: Bittu Ray | Owner: (none)
Type: Uncategorized | Status: closed
Component: Core (Cache system) | Version: 4.2
Severity: Normal | Resolution: invalid
Keywords: Django 4.2, Cache | Triage Stage:
error, Redis Cache, Pickle | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Bittu Ray):

Hi,
This is not related to Django redis, I am getting this issue even with the
other django redis library (The library which is recommended on Django
page as well
[here]https://docs.djangoproject.com/en/4.2/topics/cache/#redis), also
this issue is not arising on local and staging environment, it's occurring
in the production environment only (with the same code)
--
Ticket URL: <https://code.djangoproject.com/ticket/36033#comment:2>

Django

unread,
Dec 22, 2024, 8:08:11 PM12/22/24
to django-...@googlegroups.com
#36033: Getting TypeError: cannot pickle 'dict_values' object Error with Django
4.2.16
-------------------------------------+-------------------------------------
Reporter: Bittu Ray | Owner: (none)
Type: Uncategorized | Status: closed
Component: Core (Cache system) | Version: 4.2
Severity: Normal | Resolution: invalid
Keywords: Django 4.2, Cache | Triage Stage:
error, Redis Cache, Pickle | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Tim Graham):

You still have not provided a way to reproduce the issue and demonstrated
that Django is at fault. I see a reference to django_select2 so it could
be related to that library. You need to debug the issue or get help doing
so using the support channels I linked.
--
Ticket URL: <https://code.djangoproject.com/ticket/36033#comment:3>

Django

unread,
Dec 23, 2024, 6:37:02 AM12/23/24
to django-...@googlegroups.com
#36033: Getting TypeError: cannot pickle 'dict_values' object Error with Django
4.2.16
-------------------------------------+-------------------------------------
Reporter: Bittu Ray | Owner: (none)
Type: Uncategorized | Status: closed
Component: Core (Cache system) | Version: 4.2
Severity: Normal | Resolution: invalid
Keywords: Django 4.2, Cache | Triage Stage:
error, Redis Cache, Pickle | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Bittu Ray):

I am providing here how to reproduce it


{{{
from django.core.cache import cache

val = {"a":1, "b":2, "c":3}
queryset = Record.objects.filter(id__in=val.values())
cache.set("key", queryset)
}}}

Try this, you will get this error dict_values cannot be pickled, while in
Django 3.2 it's working fine
--
Ticket URL: <https://code.djangoproject.com/ticket/36033#comment:4>

Django

unread,
Dec 23, 2024, 11:35:44 AM12/23/24
to django-...@googlegroups.com
#36033: Getting TypeError: cannot pickle 'dict_values' object Error with Django
4.2.16
-------------------------------------+-------------------------------------
Reporter: Bittu Ray | Owner: (none)
Type: Uncategorized | Status: closed
Component: Core (Cache system) | Version: 4.2
Severity: Normal | Resolution: invalid
Keywords: Django 4.2, Cache | Triage Stage:
error, Redis Cache, Pickle | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Simon Charette):

Not sure what to say other than what the exception points at. If you plan
on pickling an object then you must make sure it's pickleable so the
obvious solution here to do

{{{#!python
queryset = Record.objects.filter(id__in=list(val.values()))
}}}

AFAIK Django doesn't provide any guarantees on how it stores lookup right-
hand-sides internally so if it happened to work in 3.2 (I haven't verified
it's the case) it was an implementation detail.
--
Ticket URL: <https://code.djangoproject.com/ticket/36033#comment:5>
Reply all
Reply to author
Forward
0 new messages