Fix automatic provisioning of Postgres DB addons#1375
Conversation
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.
|
I've also updated the Buildpack API docs to mention this caveat for |
|
Thanks for the prompt fix, and the thorough writeup. I hope you don't mind a brief followup. First, your description of the core issue made me feel better about not being able to find a fix myself. I had hoped to make a quick fix and file a PR instead of an issue, but it was deeper than I could dig in a reasonable time. Can you tell me where Second, this surprised me: "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 talk to a lot of Django teachers/mentors, and one of our shared frustrations about most platforms is that their demo Django project doesn't even use a database. But the python-getting-started repo does have a tiny model and a page that saves an instance of the model. Can't you write a test script that deploys this project, and tests that the db page is rendered successfully? It's an interesting test to write, when you're testing the full deployment process. Heroku's gotten a bit of heat recently, but I'm really happy to see changes made that need to happen for long-term sustainability. Your writeup of issues like this are a great example of what corporate open source can look like. Thanks again! |
|
Hi! No problem :-)
The Heroku build system itself calls Longer term, we're going to migrate from the current buildpacks/build system to Cloud Native Buildpacks (https://buildpacks.io), which can more easily be run locally (using the Pack CLI), and moving much of the build system logic out of Heroku-only codebases, which will make reproducing and testing things much easier.
Yes we could. The issue is that the Ideally the build system would report in the build log what the |
|
Thank you so much, this is really helpful. :) |
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
exportscript prior to runningbin/release(like it does when running subsequent buildpacks), and so the buildpack configured env vars (such asPATH) are not set.This meant that when
bin/releaseused theis_module_availableutility, 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 migratecommand. However it seems the Django config for that project silently falls back to sqlite ifDATABASE_URLis not set - so the project (and the migrate command) still worked.For this PR I have manually tested to ensure the addon itself appears on the app.
Fix #1374.
GUS-W-11851647.