-
-
Notifications
You must be signed in to change notification settings - Fork 207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support unix socket path as host in database url #132
Comments
Readme states you can use |
Workaround: You need to encode the HOST part of DATABASE_URL string and then decode again: import dj_database_url, urllib.parse
# "postgres://" + user + ":" + password + "@" + urllib.parse.quote("/cloudsql/project_id:region:instance_id") + "/" + database
database_url = "postgres://user:password@%2Fcloudsql%2Fproject_id%3Aregion%3Ainstance_id/database"
config = dj_database_url.parse(database_url)
# {
# 'NAME': 'database',
# 'USER': 'user',
# 'PASSWORD': 'password',
# 'HOST': '/cloudsql/project_id%3Aregion%3Ainstance_id',
# 'PORT': '',
# 'CONN_MAX_AGE': 0,
# 'ENGINE': 'django.db.backends.postgresql_psycopg2'
# }
config['HOST'] = urllib.parse.unquote(config['HOST'])
# "/cloudsql/project_id:region:instance_id"
then works! |
jared-hardy
added a commit
to jared-hardy/dj-database-url
that referenced
this issue
Oct 6, 2021
Add synthetic test correlating to Google Cloud SQL connector socket, to make sure Issue jazzband#132 is solved.
palfrey
pushed a commit
that referenced
this issue
Dec 12, 2022
* Use URL Parse library to decode % encodes Use URL Parse library for what it's good for: to decode % URL encode strings. Don't do it here -- we're already importing a better library for that! * Test revision with Google Cloud SQL connector Add synthetic test correlating to Google Cloud SQL connector socket, to make sure Issue #132 is solved Co-authored-by: jared-hardy <jaredhardy@gmail.com>
Solved by #181 |
LilaKelland
added a commit
to PHACDataHub/cloudrun-deployment-example
that referenced
this issue
Jun 16, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When running Django applications on Google Cloud serverless products: App Engine, Cloud Functions, and most recently Cloud Run, connecting to Cloud SQL instances requires the use of a unix socket as the database host. This works fine using the traditional
DATABASES
dict in the settings file:However
dj-database-url
doesn't seem to be able to recognize the unix socket path as the host:The text was updated successfully, but these errors were encountered: