Opened 8 years ago

Closed 7 years ago

Last modified 5 years ago

#10197 closed (fixed)

Foriegn Key breaks pickling of QuerySet

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


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 8 years ago.
Regression test demonstrating failure

Download all attachments as: .zip

Change History (12)

comment:1 Changed 8 years ago by anonymous

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

comment:2 Changed 8 years ago by Russell Keith-Magee

Triage Stage: UnreviewedAccepted

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

comment:3 Changed 8 years ago by Russell Keith-Magee

milestone: 1.1 beta

Changed 8 years ago by Bob Thomas

Attachment: 10197_regression.diff added

Regression test demonstrating failure

comment:4 Changed 8 years ago by Bob Thomas

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 Changed 7 years ago by Russell Keith-Magee

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

comment:6 Changed 7 years ago by wfagan@…

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 Changed 7 years ago by Alex Gaynor

The issue here is the storage of the foreign key on the Aggregation object, which is created here: (line 90).

comment:8 Changed 7 years ago by Russell Keith-Magee

Resolution: fixed
Status: newclosed

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

comment:9 Changed 7 years ago by noisyboiler

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 Changed 7 years ago by Russell Keith-Magee

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 Changed 5 years ago by Jacob

milestone: 1.2

Milestone 1.2 deleted

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