Opened 4 weeks ago

Closed 4 weeks ago

Last modified 4 weeks ago

#36033 closed Uncategorized (invalid)

Getting TypeError: cannot pickle 'dict_values' object Error with Django 4.2.16

Reported by: Bittu Ray Owned by:
Component: Core (Cache system) Version: 4.2
Severity: Normal Keywords: Django 4.2, Cache error, Redis Cache, Pickle
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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.

Change History (5)

comment:1 by Tim Graham, 4 weeks ago

Resolution: invalid
Severity: Release blockerNormal
Status: newclosed

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.

comment:2 by Bittu Ray, 4 weeks ago

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)

comment:3 by Tim Graham, 4 weeks ago

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.

comment:4 by Bittu Ray, 4 weeks ago

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

comment:5 by Simon Charette, 4 weeks ago

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

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.

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