#12924 closed (fixed)
Pickling QuerySet with related fields fails
Reported by: | Dmitry Shevchenko | Owned by: | Alex Gaynor |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.2-beta |
Severity: | Keywords: | ||
Cc: | dmishe@…, sj@… | Triage Stage: | Accepted |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Assume we have two related models:
from django.db import models class Group(models.Model): title = models.CharField(max_length=10) class Event(models.Model): group = models.ForeignKey('Group')
Pickling queryset with filtering by group then fails:
>>>pickle.dumps(Event.objects.filter(group=1)) PicklingError: Can't pickle <function _curried at 0x101fdd5f0>: it's not found as django.utils.functional._curried
However, if i specify that i'm filtering on __pk
lookup, then it suddenly works:
pickle.dumps(Event.objects.filter(group__pk=1))
Attachments (3)
Change History (12)
comment:1 by , 15 years ago
Version: | 1.1 → 1.2-beta |
---|
comment:2 by , 15 years ago
comment:3 by , 15 years ago
milestone: | → 1.2 |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:4 by , 15 years ago
Component: | Uncategorized → Database layer (models, ORM) |
---|
comment:5 by , 15 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
by , 15 years ago
Attachment: | translation-wtf-party.diff added |
---|
Initial version, seems to be working, fixes all teh tickets about pickling translatable strings as well.
comment:6 by , 15 years ago
Let me point out that there's an important difference in behaviour in of delayed loading in Alex's patch. Namely, as with Alex's, Malcolm's code installs the reference to delayed_loader()
as a proxy for every real translation function. But when delayed_loader()
runs, it substitutes the references to itself with the actual functions from the imported real translation module in Malcolm's version. So it will be called exactly once and function calls will be fast subsequently.
As of now, Alex's version retains the references so that all calls to translation functions actually pass through delayed_loader()
. As
- calls to translation functions are frequent and
import
s inside a function make calling it rather slow compared with a simple proxy function call (which is somewhat unexpected -- one would assume that only the first call toimport
is expensive and others cheap once the module is loaded -- but onlytimeit
will tell as they say :) )
I recommend retaining Malcolm's optimized version. Currying is fine though and makes the code more readable IMHO.
See discussion at http://botland.oebfare.com/logger/django-dev/2010/3/20/3/ .
comment:7 by , 15 years ago
Cc: | added |
---|
by , 15 years ago
Attachment: | translation-wtf-party.2.diff added |
---|
Added some forgotten files (tests), also updated some comments.
comment:8 by , 15 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Ok found this evil function :)