Opened 15 years ago

Closed 14 years ago

Last modified 12 years ago

#10197 closed (fixed)

Foriegn Key breaks pickling of QuerySet

Reported by: james@… Owned by: nobody
Component: Core (Cache system) Version: dev
Severity: Keywords: pickle, queryset, annotate
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I'm using the latest version from svn (as of 1-4-09) and python2.5. I'm trying to pickle a QuerySet that is using annotate and I'm getting the following error:

raise TypeError, "can't pickle %s objects" % base.__name__
TypeError: can't pickle function objects

Here is what I'm trying to do:
(ProductChannel has OneToMany relationship with ProductChannelImage)

pc = ProductChannel.objects.filter(supplier=supplier)
pc = pc.filter(status='new')
pc = pc.annotate(num_images=Count('productchannelimage'))
...
request.session['pc_qs'] = dumps(pc.query)

Before I added the annotation to the query it was pickling just fine.

Attachments (1)

10197_regression.diff (693 bytes ) - added by Bob Thomas 15 years ago.
Regression test demonstrating failure

Download all attachments as: .zip

Change History (12)

comment:1 by anonymous, 15 years ago

comment:2 by Russell Keith-Magee, 15 years ago

Triage Stage: UnreviewedAccepted

Problem verified, although I'm not entirely certain which function is causing the problem here.

comment:3 by Russell Keith-Magee, 15 years ago

milestone: 1.1 beta

by Bob Thomas, 15 years ago

Attachment: 10197_regression.diff added

Regression test demonstrating failure

comment:4 by Bob Thomas, 15 years ago

milestone: 1.1 beta1.1

This is just an ordinary bug, not a feature. I think it can miss the 1.1 beta.

comment:5 by Russell Keith-Magee, 15 years ago

Interesting bit of history - #7506, fixed in [7773] logged a similar problem. Might give some pointers as to the possible cause.

comment:6 by wfagan@…, 15 years ago

Sorry I am new at this. How do I subscribe to updates to this bug? Or will it do it automatically by me commenting?

comment:7 by Alex Gaynor, 15 years ago

The issue here is the storage of the foreign key on the Aggregation object, which is created here: http://code.djangoproject.com/browser/django/trunk/django/db/models/fields/related.py#L86 (line 90).

comment:8 by Russell Keith-Magee, 15 years ago

Resolution: fixed
Status: newclosed

(In [10522]) Fixed #10197 -- Corrected pickling of querysets when a subset of fields was selected.

comment:9 by noisyboiler, 14 years ago

Component: Database layer (models, ORM)Cache system
milestone: 1.11.2
Needs tests: set
Resolution: fixed
Status: closedreopened
Summary: Annotate breaks pickling of QuerySetForiegn Key breaks pickling of QuerySet
Triage Stage: AcceptedUnreviewed

I'm having problems pickling Querysets to cache with memcached. As soon as a relationship is followed we get:
Exception Type: TypeError
Exception Value: can't pickle function objects

This is from a simple query like:
cars = Car.objects.filter(advertcarisnull=False)

Have tried on 1.2 beta and numerous suggested SVN checkouts, all yield the same result.

Some other cache backend options are okay.

comment:10 by Russell Keith-Magee, 14 years ago

Resolution: fixed
Status: reopenedclosed

Please don't reopen tickets that were closed with a patch. You may be seeing a *similar* problem, but I can guarantee it's not the *same* problem, because the patch that was committed has a regression test that isn't failing.

I'm going to guess you're actually looking for #12924. If that ticket doesn't describe your problem, please open a new ticket with a complete set of reproduction instructions.

comment:11 by Jacob, 12 years ago

milestone: 1.2

Milestone 1.2 deleted

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