1

I'm trying to store a date into memcache using the following code:

from datetime import date
from google.appengine.api.memcache import Client

MEMCACHE_DATE_KEY = 'date'

client = Client()

def last_date():
    return client.get(MEMCACHE_DATE_KEY)

def new_date():
    client.set(MEMCACHE_DATE_KEY, date.today())

I am getting this error:

Traceback (most recent call last):
  File "manage.py", line 4, in 
    setup_env(manage_py_env=True)
  File "/Users/benji/Projects/app-engine-patch-sample/common/appenginepatch/aecmd.py", line 67, in setup_env
    patch_all()
  File "/Users/benji/Projects/app-engine-patch-sample/common/appenginepatch/appenginepatcher/patch.py", line 29, in patch_all
    patch_app_engine()
  File "/Users/benji/Projects/app-engine-patch-sample/common/appenginepatch/appenginepatcher/patch.py", line 520, in patch_app_engine
    db.Model._meta = _meta(db.Model, ())
  File "/Users/benji/Projects/app-engine-patch-sample/common/appenginepatch/appenginepatcher/patch.py", line 258, in __init__
    settings.INSTALLED_APPS
  File "/Users/benji/Projects/share-renting-engine/common/zip-packages/django-1.1.zip/django/utils/functional.py", line 269, in __getattr__
  File "/Users/benji/Projects/share-renting-engine/common/zip-packages/django-1.1.zip/django/conf/__init__.py", line 40, in _setup

  File "/Users/benji/Projects/share-renting-engine/common/zip-packages/django-1.1.zip/django/conf/__init__.py", line 73, in __init__

  File "/Users/benji/Projects/share-renting-engine/common/zip-packages/django-1.1.zip/django/utils/importlib.py", line 35, in import_module
  File "/Users/benji/Projects/share-renting-engine/settings.py", line 120, in 
    from ragendja.settings_post import *
  File "/Users/benji/Projects/app-engine-patch-sample/common/appenginepatch/ragendja/settings_post.py", line 98, in 
    check_app_imports(app)
  File "/Users/benji/Projects/app-engine-patch-sample/common/appenginepatch/ragendja/settings_post.py", line 63, in check_app_imports
    __import__(app, {}, {}, [''])
  File "/Users/benji/Projects/share-renting-engine/engine/__init__.py", line 5, in 
    if date.today() != last_date():
  File "/Users/benji/Projects/share-renting-engine/engine/utils/date.py", line 12, in last_date
    return client.get(MEMCACHE_DATE_KEY)
  File "/Users/benji/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/memcache/__init__.py", line 428, in get
    self._make_sync_call('memcache', 'Get', request, response)
  File "/Users/benji/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/apiproxy_stub_map.py", line 86, in MakeSyncCall
    return stubmap.MakeSyncCall(service, call, request, response)
  File "/Users/benji/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/apiproxy_stub_map.py", line 279, in MakeSyncCall
    assert stub, 'No api proxy found for service "%s"' % service
AssertionError: No api proxy found for service "memcache"

How can i use memcache with app-engine-patch?

Thanks for your time.

Benjamin
  • 617
  • 13
  • 27

1 Answers1

1

It looks like you're attempting to make a memcache call at import time. Judging from the stacktrace, Django imports your modules before it sets up the App Engine environment, and therefore any calls to App Engine services at the module level will fail on the development server.

Move the call to memcache inside a function that's called from a request handler, and it should resolve your problem.

Nick Johnson
  • 100,655
  • 16
  • 128
  • 198
  • @Benjamin Incidentally, this is clearly a bug in Django-nonrel, since it results in the development environment not behaving the same as production. You might want to file a bug with them to that effect. – Nick Johnson Feb 02 '11 at 05:59
  • I have contacted them. Thanks for your help. – Benjamin Feb 02 '11 at 06:46
  • 1
    Bejamin, you're using app-engine-patch and not not Django-nonrel and since app-engine-patch isn't maintained, anymore, I'm afraid you'll have to fix this bug on your own. If that's possible for you I'd suggest that you switch to Django-nonrel. – Waldemar Kornewald Feb 02 '11 at 07:24
  • @Waldemar Sorry, my bad advice - I thought he was using django-nonrel for some reason. – Nick Johnson Feb 02 '11 at 23:15