#24381 closed Bug (fixed)
Cache pickling exception in 1.8a1 with cross-table filter params
Reported by: | Mark Tranchant | Owned by: | Tim Graham |
---|---|---|---|
Component: | Core (Cache system) | Version: | 1.8alpha1 |
Severity: | Release blocker | Keywords: | cache pickle empty queryset |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
In 1.7.4 (and prior versions back to at least 2011), I can run the following transcript in ../manage.py shell. The Contributor model has two ForeignKeys, to MyModel and Task, so I'm looking up all MyModels which have a referring contributor associated with task 4.
>>> from MyProject.models import * >>> from django.core.cache import cache >>> cl = MyModel.objects.filter(contributor__task__id=4) >>> cl <<< [] >>> type(cl) <<< django.db.models.query.QuerySet >>> cache.set('testing', cl) >>> cache.get('testing') <<< []
In 1.8a1, the cache set operation generates an exception. See attachment for trace.
PicklingError: Can't pickle <type 'module'>: it's not found as __builtin__.module
If I try to cache a simple empty QuerySet (MyModel.objects.filter(id=0), for example), it works.
Attachments (2)
Change History (15)
by , 10 years ago
Attachment: | pickling-error.txt added |
---|
comment:1 by , 10 years ago
Summary: | Cache pickling issue in 1.8a1 → Cache pickling exception in 1.8a1 |
---|
comment:2 by , 10 years ago
Description: | modified (diff) |
---|
comment:3 by , 10 years ago
Description: | modified (diff) |
---|---|
Summary: | Cache pickling exception in 1.8a1 → Cache pickling exception in 1.8a1 with cross-table filter params |
comment:4 by , 10 years ago
Description: | modified (diff) |
---|
comment:5 by , 10 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
Triage Stage: | Unreviewed → Accepted |
Bisected to f233bf47dde1d481108142c8d6b4bb3b3d8c6d08. Adding test and continuing investigation.
by , 10 years ago
Attachment: | 24381-test.diff added |
---|
comment:6 by , 10 years ago
The app registry is trying to be pickled and the module that cannot be pickled in my test is from:
<ContentTypesConfig: contenttypes> {'models_module': <module 'django.contrib.contenttypes.models' from '/home/tim/code/django/django/contrib/contenttypes/models.py'>, 'name': 'django.contrib.contenttypes', 'models': OrderedDict([('contenttype', <class 'django.contrib.contenttypes.models.ContentType'>)]), 'module': <module 'django.contrib.contenttypes' from '/home/tim/code/django/django/contrib/contenttypes/__init__.py'>, 'label': 'contenttypes', 'path': u'/home/tim/code/django/django/contrib/contenttypes'}
I think the solution is to figure out why that's now happening and to prevent it (assuming it can be avoided without loss of functionality).
comment:7 by , 10 years ago
Has patch: | set |
---|
PR (might be able to be improved by someone more knowledgeable about pickle). Mark, could you test and verify it also solves your issue?
comment:8 by , 10 years ago
As Loic mentiond on IRC, a general mechanism for excluding cached_properties from pickling could be useful, but it's a bit out of the scope of solving this issue.
comment:9 by , 10 years ago
I can confirm that adding the __getstate__
function as in the patch to stock 1.8a1 from PyPl fixes my issue, and allows my entire test suite to run without error.
Thanks!
comment:10 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Exception trace