-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Django tutorial for App Engine is broken #10653
Description
The section in the following App Engine quickstart references a variable in the code USE_CLOUD_SQL_AUTH_PROXY that only works locally and not when deploying to App Engine.
# Use django-environ to parse the connection string
DATABASES = {"default": env.db()}
# If the flag as been set, configure to use proxy
if os.getenv("USE_CLOUD_SQL_AUTH_PROXY", None):
DATABASES["default"]["HOST"] = "127.0.0.1"
DATABASES["default"]["PORT"] = 5432The flag sets the host and port of the database connection to expect a local TCP connection. This works for the local deployment of the app as the quickstart prompts the user to run the Cloud SQL Auth Proxy locally configured with TCP.
However, if this flag is set when deploying the code to App Engine it breaks the sample. App Engine is automatically configured with the Cloud SQL Auth Proxy but the Proxy in a serverless environment is configured to use Unix sockets not a TCP connection.
The .env file used in the quickstart sets the database connection to use the proper Unix socket configuration (/cloudsql/PROJECT_ID:REGION:INSTANCE_NAME) in a previous step.
echo DATABASE_URL=postgres://DATABASE_USERNAME:DATABASE_PASSWORD@//cloudsql/PROJECT_ID:REGION:INSTANCE_NAME/DATABASE_NAME > .envHowever, the use of the USE_CLOUD_SQL_AUTH_PROXY flag overrides this proper value and breaks the sample.
Noted by a SO user: https://stackoverflow.com/questions/77164817/django-app-on-google-app-engine-not-connecting-to-google-cloud-sql/77172777