views:

79

answers:

1

I am developing an App Engine App that uses memcache. Since there is only a single memcache shared among all versions of your app I am potentially sending bad data from a new version to the production version memcache. To prevent this, I think I may append the app version to the memcache key string to allow various versions of the app to keep their data separate.

I could do this manually, but I'd like to pull in the version from the app.yaml

How can I access the app version from within the python code?

+5  A: 

The os.environ variable contains a key called CURRENT_VERSION_ID that you can use. It's value is composed of the version from app.yaml concatenated together with a period and what I suspect is the api_version. If I set version to 42 it gives me the value of 42.1. You should have no problems extracting the version number alone, but it might not be such a bad idea to keep the api_version aswell.

EDIT:

@Nick Johnson has pointed out that the number to the right of the period is the minor version, a number which is incremented each time you deploy your code. On the development server this number is always 1.

klausbyskov
thanks, I'm going to call os.environ.get('CURRENT_VERSION_ID','')
Ryan Bavetta
The second part of the version is the 'minor' version ID. On the development server it's always 1, but in production it changes with every deploy.
Nick Johnson
@Nick Johnson, thanks for pointing that out. That is very good to know.
klausbyskov