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

Not clear how to reference HEROKU_POSTGRESQL_GREEN_URL and other color db variables. #221

Closed
DavidPratten opened this issue May 18, 2024 · 7 comments · Fixed by #224
Closed

Comments

@DavidPratten
Copy link

While https://github.com/heroku/python-getting-started/blob/main/gettingstarted/settings.py says

`DATABASE_URL` will be set automatically by Heroku when a database addon is attached to your Heroku app.

in actual fact this wasn't true in my case. The variable was called HEROKU_POSTGRESQL_GREEN_URL

I expect that future noobie users will be assisted if the example calls out the variability in the naming of the DATABASE_URL environment variable and shows how to discover what it is called and how to incorporate the actual name.

Something like this:

if IS_HEROKU_APP:
    # In production on Heroku the database configuration is derived from a `DATABASE_URL` 
    # environment variable by the dj-database-url package. `DATABASE_URL` or a similar color variable will be set
    # automatically by Heroku when a database addon is attached to your Heroku app. 
    # Run 'heroku config' to find the name of your `DATABASE_URL` and update the code below. See:
    # https://devcenter.heroku.com/articles/provisioning-heroku-postgres
    # https://github.com/jazzband/dj-database-url
    DATABASES = {
        "default": dj_database_url.config(
            env='DATABASE_URL',
            conn_max_age=600,
            conn_health_checks=True,
            ssl_require=True,
        ),
    }
@edmorley
Copy link
Member

edmorley commented May 20, 2024

@DavidPratten Hi! Thank you for the feedback.

The default env var is always named DATABASE_URL for the first database added to the app. The additional colour name variants are only seen when multiple databases are added, per:
https://devcenter.heroku.com/articles/provisioning-heroku-postgres#application-config-vars

In your case, were you intentionally using multiple databases (and so wanting to understand how to adapt this codebase for that use-case), or were you following the tutorial and had accidentally added multiple DBs?

@DavidPratten
Copy link
Author

DavidPratten commented May 20, 2024 via email

@edmorley
Copy link
Member

Hi David

If you run heroku addons, do you see several DB addons now?

Also, was your Heroku account created before May 15, 2023? Since older accounts have a legacy auto-provisioning feature enabled, though the tutorial content on Dev Center has been written in such a way that the auto-provisioning shouldn't occur for older accounts, so long as the tutorial is followed in sequence.

@DavidPratten
Copy link
Author

Hi Ed,

No. Its a new account. When I created my instance, I created just a single database, and only once, and Heroku added it as a color name.

David

edmorley added a commit that referenced this issue May 24, 2024
In cases where something other than the `DATABASE_URL` needs
to be set, it was previously hard to know how to customise
`dj-database-url`'s config, since the upstream docs don't mention the
`env` option.

Now our default config passes an explicit value for `env` (which matches
the default value for that argument), to improve discoverability.

In addition, the Heroku Postgres docs link has been updated to deep link
to the env vars section, which explains when/why DB env vars will be given
alternate colour-prefixed names.

Closes #221.
@edmorley
Copy link
Member

Ok that's very strange - not sure what happened in your case.

I've just merged #224 which hopefully improves the UX in this case.

@edmorley
Copy link
Member

I also filed jazzband/dj-database-url#248

@DavidPratten
Copy link
Author

DavidPratten commented May 24, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants