geodjango test runner database creation error handling
|Reported by:||yourcelf||Owned by:||nobody|
|Severity:||Keywords:||geodjango test errors documentation|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
The geodjango testrunner assumes that any failure at database creation is the result of the database already existing, resulting in the message:
It appears that the database, test_foobar, already exists. Type 'yes' to delete it, or 'no' to cancel:
This message appears even when the test database does not exist. If one types "yes", the test runner attempts to drop the non-existent database and errors out, hiding the actual error that prevented database creation.
One example of another reason the database creation might fail is if the user does not have copy privileges for the template database.
When using the "POSTGIS_TEMPLATE" setting, the geodjango testrunner attempts to copy the template database to create the new test database. Without copy privileges, this fails. In postgresql, if the database user is not the owner of POSTGIS_TEMPLATE, the user will not have copy privileges unless "datistemplate" is set to "true" for the template database.
A couple ways to improve this situation:
- Improving the documentation to indicate that when setting up the template database, it is necessary to set "datistemplate" to true, for example:
UPDATE pg_database SET datistemplate = true WHERE datname = 'template_postgis';
- Checking to see if the error in database creation is actually a result of there being a pre-existing table, and if not, giving a more appropriate error message.
- Changing the "DROP DATABASE" query to an appropriate "DROP DATABASE IF EXISTS" type query, with the assumption that any further creation error should do the right thing.