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

Provision a Heroku Postgres DB in fewer cases #1363

Merged
merged 1 commit into from
Sep 22, 2022
Merged

Conversation

edmorley
Copy link
Member

As part of the Buildpack API, a buildpack can request the provisioning of addons on the first build of an app via the bin/release payload. (This feature does not apply to subsequent builds of existing apps.)

Previously the Python buildpack requested a Heroku Postgres DB be provisioned if the app source contained a manage.py file in the source root or any subdirectory up to three levels deep.

This meant a Postgres DB was provisioned even in cases where the app wasn't a Django app (but just happened to have a manage.py script) or used an alternative DB backend (eg MySQL), or didn't use a DB at all.

Now, the DB is only provisioned if all of the following are true:

  • a manage.py file exists in the root of the app source
  • django is installed
  • psycopg2 is installed

This ensures it's still provisioned in the Python getting-started guide case (and any other similar cases), but not in the other scenarios mentioned above.

Fixes #1067.
GUS-W-8098791.

As part of the Buildpack API, a buildpack can request the provisioning
of addons on the first build of an app via the `bin/release` payload.
(This feature does not apply to subsequent builds of existing apps.)

Previously the Python buildpack requested a Heroku Postgres DB be
provisioned if the app source contained a `manage.py` file in the
source root or any subdirectory up to three levels deep.

This meant a Postgres DB was provisioned even in cases where the
app wasn't a Django app (but just happened to have a `manage.py`
script) or used an alternative DB backend (eg MySQL), or didn't use
a DB at all.

Now, the DB is only provisioned if all of the following are true:
- a `manage.py` file exists in the root of the app source
- `django` is installed
- `psycopg2` is installed

This ensures it's still provisioned in the Python getting-started guide
case (and any other similar cases), but not in the other scenarios
mentioned above.

Fixes #1067.
GUS-W-8098791.
@edmorley edmorley added the bug label Sep 21, 2022
@edmorley edmorley self-assigned this Sep 21, 2022
@edmorley edmorley marked this pull request as ready for review September 21, 2022 21:57
@edmorley edmorley requested a review from a team as a code owner September 21, 2022 21:57
@edmorley edmorley merged commit cd62671 into main Sep 22, 2022
@edmorley edmorley deleted the stricter-addon-install branch September 22, 2022 15:31
@edmorley
Copy link
Member Author

edmorley added a commit that referenced this pull request Oct 4, 2022
In #1363 the logic for determining when to automatically provision
a Heroku Postgres database addon was adjusted to reduce false
positives.

Unfortunately, this broke provisioning in all cases, since it turns
out that the build system does not source the `export` script prior
to running `bin/release` (like it does when running subsequent
buildpacks), and so the buildpack configured env vars (such as `PATH`
are not set.

This meant that when `bin/release` used the `is_module_available`
utility, it was calling system Python (where the Django and psycopg2
packages were not installed) and so always failing the conditional.

Unfortunately we do not currently have an easy way to test `bin/release`,
otherwise a test case would have been added in the original PR.

I had manually tested the original PR using the Python getting started
guide, but had only checked via accessing the app and trying to run
the Django `./manage.py migrate` command. However it seems the
Django config for that project silently falls back to sqlite if `DATABASE_URL`
is not set - so the project still worked.

For this PR I have manually tested to ensure the addon appears on the app.

 GUS-W-11851647.
edmorley added a commit that referenced this pull request Oct 4, 2022
In #1363 the logic for determining when to automatically provision
a Heroku Postgres database addon was adjusted to reduce false
positives.

Unfortunately, this broke provisioning in all cases, since it turns
out that the build system does not source the `export` script prior
to running `bin/release` (like it does when running subsequent
buildpacks), and so the buildpack configured env vars (such as `PATH`
are not set.

This meant that when `bin/release` used the `is_module_available`
utility, it was calling system Python (where the Django and psycopg2
packages were not installed) and so always failing the conditional.

Unfortunately we do not currently have an easy way to test `bin/release`,
otherwise a test case would have been added in the original PR.

I had manually tested the original PR using the Python getting started
guide, but had only checked via accessing the app and trying to run
the Django `./manage.py migrate` command. However it seems the
Django config for that project silently falls back to sqlite if `DATABASE_URL`
is not set - so the project still worked.

For this PR I have manually tested to ensure the addon appears on the app.

Fix #1374.
GUS-W-11851647.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Skip the default heroku-postgresql addon if a Postgres DB driver isn't installed
2 participants