Opened 7 years ago

Closed 6 years ago

Last modified 4 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 bthomas 7 years ago.
Regression test demonstrating failure

Download all attachments as: .zip

Change History (12)

comment:1 Changed 7 years ago by anonymous

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 7 years ago by russellm

  • Triage Stage changed from Unreviewed to Accepted

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

comment:3 Changed 7 years ago by russellm

  • milestone set to 1.1 beta

Changed 7 years ago by bthomas

Regression test demonstrating failure

comment:4 Changed 7 years ago by bthomas

  • milestone changed from 1.1 beta to 1.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 russellm

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

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 russellm

  • Resolution set to fixed
  • Status changed from new to closed

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

comment:9 Changed 6 years ago by noisyboiler

  • Component changed from Database layer (models, ORM) to Cache system
  • milestone changed from 1.1 to 1.2
  • Needs tests set
  • Resolution fixed deleted
  • Status changed from closed to reopened
  • Summary changed from Annotate breaks pickling of QuerySet to Foriegn Key breaks pickling of QuerySet
  • Triage Stage changed from Accepted to Unreviewed

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 6 years ago by russellm

  • Resolution set to fixed
  • Status changed from reopened to closed

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 4 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 deleted

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