﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
24862	Patch for GeoDjango to improve error message if database connection is bad	brycenesbitt	nobody	"For a project with GeoDjango fi the database is completely down, you'll get exception:

{{{
django.core.exceptions.ImproperlyConfigured: Cannot determine PostGIS version for database ""umap"" . GeoDjango requires at least PostGIS version 1.3. Was the database created from a spatial database template?
}}}

This patch first does a trivial database connection to flesh out the real exception, before checking the PostGIS version number:


{{{
***************
*** 246,256 ****
          # comprising user-supplied values for the major, minor, and
          # subminor revision of PostGIS.
- 
-         # First connect to the database trivially
-         # This prevents raising a GeoDjango exception below if the connection is bad
-         with self.connection.temporary_connection() as cursor:
-             cursor.execute('SELECT version()')
- 
-         # Now check PostGIS
          if hasattr(settings, 'POSTGIS_VERSION'):
              version = settings.POSTGIS_VERSION
--- 246,249 ----
***************
*** 260,265 ****
              except DatabaseError:
                  raise ImproperlyConfigured(
!                     'Cannot determine PostGIS version for database ""%s"" '
!                     'using command ""SELECT postgis_lib_version()"". '
                      'GeoDjango requires at least PostGIS version 1.3. '
                      'Was the database created from a spatial database '
--- 253,257 ----
              except DatabaseError:
                  raise ImproperlyConfigured(
!                     'Cannot determine PostGIS version for database ""%s"". '
                      'GeoDjango requires at least PostGIS version 1.3. '
                      'Was the database created from a spatial database '

}}}
"	Cleanup/optimization	new	GIS	1.8	Normal		PostGIS, GeoDjango, GIS, Usability		Unreviewed	1	0	0	0	1	0
