Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8877093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:22:52+00:00 2026-06-14T19:22:52+00:00

I’m trying to use memcache for the first time on App Engine and am

  • 0

I’m trying to use memcache for the first time on App Engine and am hitting a “PicklingError”.

The first place I’ve tried memcache is on the site’s home page where I grab content from the datastore:

def get(self):
    content = memcache.get('home:content')
    if content is None:
        all_content = Content.all()
        all_content.order("-views")
        all_content.filter('published =', True)
        content = all_content.run(batch_size=5, limit=5)
        memcache.add(key='home:content', value=content, time=120)

(Note that this works fine without me trying to put the content Query object into memcache. Here’s the error it hits on the last line (memcache.add…):

PicklingError: Pickling of datastore_query.Batcher is unsupported.

Here’s the model for Content:

class Content(db.Model):
    category = db.StringProperty(required = True)
    content_type = db.StringProperty(required = True)
    published = db.BooleanProperty(default = False)
    title = db.StringProperty(required = True)
    abstract = db.TextProperty(required = True)
    summary = db.TextProperty(required = True)
    URL = db.LinkProperty(required = True)
    youtube_id = db.StringProperty(required = False)
    thumbnail = db.LinkProperty(required = True)
    post_author = db.StringProperty(required = True)
    author_url = db.LinkProperty(required = False)
    date_post = db.DateTimeProperty(required = True, auto_now_add = True)
    date_source = db.DateTimeProperty(required = False)    
    # todo: split out to use decent shardedcounter approach
    views = db.IntegerProperty(default = 0)
    up_votes = db.IntegerProperty(default = 0)
    down_votes = db.IntegerProperty(default = 0)    
    def votes(self):
        return self.up_votes - self.down_votes

I’m struggling to figure out what a PicklingError is and how that might relate to trying to store a Query object into memcache. My questions:
What am I doing wrong?
Is this because I’m trying to cache the iterator?
Is there any value in caching the Query object and needing to call .run() on it every page load?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:22:53+00:00Added an answer on June 14, 2026 at 7:22 pm

    Have a look at the source for memcache.

    In a nutshell, this occurs because your value has to be serialized in a simple way, so by default pickle (actually cPickle) is used to serialize the object you pass in.

    When add is called, _set_with_policy is called which subsequently calls _set_multi_async_with_policy. In _set_multi_async_with_policy, the key-value pairs are passing in as mapping and are serialized in a loop:

    for key, value in mapping.iteritems():
      server_key = _key_string(key, key_prefix, user_key)
      stored_value, flags = _validate_encode_value(value, self._do_pickle)
    

    In the helper method _validate_encode_value, if the object passed in is not something recognizable such as int, bool, str, the method attempts to pickle the object:

    else:
      stored_value = do_pickle(value)
      flags |= TYPE_PICKLED
    

    UPDATE: When you call run you get an iterator object back which contains certain objects contained in your query. If you’d like to pickle just the results, you can just cast this iterator to a list via

    content = list(all_content.run(batch_size=5, limit=5))
    

    If you’d like the other pieces kept around, you’ll need some sort of custom pickler. As you can see in Batcher:

      def __getstate__(self):
        raise pickle.PicklingError(
            'Pickling of datastore_query.Batch is unsupported.')
    

    most of the classes defined in datastore_query — the very same classes that define the majority of the query behavior — strongly discourage pickling by throwing a PicklingError when __getstate__ is called. If you’ve never played around with it, __getstate__ and __setstate__ are custom methods that help to pickle and unpickle objects.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
We're building an app, our first using Rails 3, and we're having to build
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm making a simple page using Google Maps API 3. My first. One marker
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.