Opened 10 years ago

Closed 10 years ago

#10452 closed (duplicate)

geodjango test runner database creation error handling

Reported by: Charlie DeTar Owned by: nobody
Component: GIS Version: master
Severity: Keywords: geodjango test errors documentation
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: 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:

  1. 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';
  1. 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.
  1. 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.

Change History (1)

comment:1 Changed 10 years ago by Jacob

Resolution: duplicate
Status: newclosed

Duplicate of #10364

Note: See TracTickets for help on using tickets.
Back to Top