Skip to content
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

Incorrect parsing of DATABASES_URL for Google Cloud MySQL #294

Closed
danielrsilveira opened this issue May 20, 2021 · 2 comments · Fixed by #334
Closed

Incorrect parsing of DATABASES_URL for Google Cloud MySQL #294

danielrsilveira opened this issue May 20, 2021 · 2 comments · Fixed by #334
Assignees
Labels
bug Something isn't working

Comments

@danielrsilveira
Copy link

I was trying to connect a Django instance to Google Cloud MySQL using django-environ in a codelab, and found an error in the parsing of DATABASES_URL for google cloud.

The url set in .env was:
DATABASE_URL="mysql://djuser:hidden-password@//cloudsql/arvore-codelab:us-central1:mysqlinstance/mydatabase"

Fix in settings.py

# Set this value from django-environ
DATABASES = {"default": env.db()}

print(DATABASES)

if "/" in DATABASES["default"]["NAME"]:
    DATABASES["default"]["HOST"], DATABASES["default"]["NAME"] = DATABASES["default"]["NAME"].rsplit('/', 1)

print(DATABASES)

Log during building in Google Cloud Build:

Step #2: ---------- EXECUTE COMMAND ----------
Step #2: python manage.py migrate
Step #2: {'default': {'NAME': '/cloudsql/arvore-codelab:us-central1:mysqlinstance/mydatabase', 'USER': 'djuser', 'PASSWORD': 'hidden-password', 'HOST': '', 'PORT': '', 'ENGINE': 'django.db.backends.mysql'}}
Step #2: {'default': {'NAME': 'mydatabase', 'USER': 'djuser', 'PASSWORD': 'hidden-password', 'HOST': '/cloudsql/arvore-codelab:us-central1:mysqlinstance', 'PORT': '', 'ENGINE': 'django.db.backends.mysql'}}
Step #2: Operations to perform:
Step #2:   Apply all migrations: admin, auth, contenttypes, myproject, sessions
Step #2: Running migrations:

This issue was discussed here googlecodelabs/feedback#964 (comment), with the help of google codelab team.

Hope this helps improving django-environ.

@sergeyklay sergeyklay self-assigned this Aug 31, 2021
@sergeyklay sergeyklay added the bug Something isn't working label Aug 31, 2021
@iflare3g
Copy link
Contributor

iflare3g commented Oct 8, 2021

Hello everyone, since it's still opened, I decided to publish my first contribution to django-environ by fixing this issue.
I hope it'll ok 😄

@sergeyklay sergeyklay linked a pull request Oct 8, 2021 that will close this issue
3 tasks
@sergeyklay
Copy link
Collaborator

This is resolved in develop branch. Thank you for the report, and for helping us make django-environ better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants