Created
April 14, 2011 17:07
-
-
Save mccutchen/919951 to your computer and use it in GitHub Desktop.
How to migrate App Engine datastore keys from one application to another
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from google.appengine.ext import db | |
def fixkey(key): | |
"""Takes a db.Key (or its string form) and checks to see if it is tied to | |
the current application. If not, the key is recreated for the current | |
application and returned as a string. | |
""" | |
app_id = os.environ.get('APPLICATION_ID') | |
if isinstance(key, basestring): | |
key = db.Key(key) | |
if key.app() != app_id: | |
newkey = db.Key.from_path(*key.to_path()) | |
else: | |
newkey = key | |
return str(newkey) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment