Memcache отсутствует в App-Engine-Patch? - PullRequest
1 голос
/ 02 февраля 2011

Я пытаюсь сохранить дату в memcache, используя следующий код:

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())

Я получаю эту ошибку:

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
<b>AssertionError: No api proxy found for service "memcache"</b>

Как я могу использовать memcache с app-engine-patch?

Спасибо за ваше время.

1 Ответ

1 голос
/ 02 февраля 2011

Похоже, вы пытаетесь сделать вызов memcache во время импорта.Судя по трассировке стека, Django импортирует ваши модули до того, как настроит среду App Engine, и поэтому любые вызовы служб App Engine на уровне модулей завершатся неудачно на сервере разработки.

Переместите вызов в memcache внутрифункция, которая вызывается из обработчика запроса и должна решить вашу проблему.

...