I'm working on an App Engine project (Python) where we'd like to make certain changes to the app's behavior when debugging/developing (most often locally). For example, when debugging, we'd like to disable our rate-limiting decorators, turn on the debug param in the WSGIApplication, maybe add some asserts.
As far as I can tell, App Engine doesn't naturally have any concept of a global dev-mode or debug-mode, so I'm wondering how best to implement such a mode. The options I've been able to come up with so far:
Use
google.appengine.api.app_identity.get_default_version_hostname()
to get the hostname and check if it begins withlocalhost
. This seems... unreliable, and doesn't allow for using the debug mode in a deployed app instance.Use
os.environ.get('APPLICATION_ID')
to get the application id, which according to this page is automatically prepended withdev~
by the development server. Worryingly, the very source of this information is in a box warning:Do not get the App ID from the environment variable. The development server simulates the production App Engine service. One way in which it does this is to prepend a string (
dev~
) to theAPPLICATION_ID
environment variable, which is similar to the string prepended in production for applications using the High Replication Datastore. You can modify this behavior with the --default_partition flag, choosing a value of "" to match the master-slave option in production. Google recommends always getting the application ID using get_application_id, as described above.Not sure if this is an acceptable use of the environment variable. Either way it's probably equally hacky, and suffers the same problem of only working with a locally running instance.
Use a custom app-id for development (locally and deployed), use the
-A
flag indev_appserver.py
, and usegoogle.appengine.api.app_identity.get_application_id()
in the code. I don't like this for a number of reasons (namely having to have two separate app engine projects).Use a
dev
app engine version for development and detect withos.environ.get('CURRENT_VERSION_ID').split('.')[0]
in code. When deployed this is easy, but I'm not sure how to make dev_appserver.py use a custom version without modifying app.yaml. I suppose I couldsed
app.yaml to a temp file in/tmp/
with the version replaced and the relative paths resolved (or just create a persistent dev-app.yaml), then pass that into dev_appserver.py. But that seems also kinda dirty and prone to error/sync issues.
Am I missing any other approaches? Any considerations I failed to acknowledge? Any other advice?