Skip to content

Django tutorial for App Engine is broken #10653

@jackwotherspoon

Description

@jackwotherspoon

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"] = 5432

The 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 > .env

However, 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

Metadata

Metadata

Assignees

Labels

priority: p2Moderately-important priority. Fix may not be included in next release.samplesIssues that are directly related to samples.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions