0

I have a google app engine application with 2 versions (master & staging) that both run on the same datastore but have different codebases.

According to my stackoverflow searches and the gae python docs the function modules.get_current_version_name() should return the version name, in my case 'staging' or 'master'.

GAE python docs

When I call it however I get a KeyError exception. It seems that when performing the actual dict lookup in os.environ or something, it tries to get a non-existing key 'CURRENT_VERSION_ID'.

Are there any steps I have to take to set up that environment variable? Is this still the correct way to get an app/modules version, or are there other options?

Kevin
  • 74,910
  • 12
  • 133
  • 166
RobbyD
  • 513
  • 3
  • 10
  • Is the `KeyError` on the dev server or App Engine? Can you post your code? `modules.get_current_version_name()` is working fine for me (using Flask, but should make no difference). – tx802 Jan 08 '16 at 13:51
  • It is running on the App Engine. This is part of a config class to set up different endpoints according to environment. I would post the code but there's pretty much nothing more. Just the 'from google.appengine.api import modules' and then 'module_version = modules.get_current_version_name()'. Afterwards I'm just updating a config dictionary according to the env. – RobbyD Jan 08 '16 at 14:30
  • Strange. The error is definitely coming from `modules.get_current_version_name()` and not your own dictionary object? – tx802 Jan 08 '16 at 15:19
  • Yes I'm 100% sure, the error only occurred after adding the get_current_version_name() while the custom dict manipulations were running perfectly fine before. It also showed that its looking for the key 'CURRENT_VERSION-ID' which I havent used anywhere. I'm now building some code that loops over the os.environ dict as that seems to be where get_current_version_name() gets its info, to see if I can use something in there to manually determine version name. But I think it's still strange, also strange that the exception isn't caught by google in their module method... – RobbyD Jan 08 '16 at 15:32
  • From looking at the source for `get_current_version_name()` you're right, so if it's not in `os.environ` then maybe it's a weird runtime environment bug? – tx802 Jan 08 '16 at 15:36
  • I've seen this error if I call the code from remote API, on the actual server it's always work so far. – marcadian Jan 09 '16 at 04:35
  • Hi, thanks for the replies. I was able to resolve my issues by simply putting it between a try except block. Apparently the function only returns a version name when it has been explicitly set during deployment. Even though google names your default version 'master' it does not return it when calling get_current_version_name() but throws an exception. Which is quite confusing and not in any documentation I came across. – RobbyD Jan 12 '16 at 08:37
  • Luckily in my case I have a test and prod env which are set up as 2 different projects (I can do env checks on project name). And my staging where version is explicitly set (but same project as production as it has to connect to the same datastore) – RobbyD Jan 12 '16 at 08:42

0 Answers0