#24862: Patch for GeoDjango to improve error message if database connection is
bad
-------------------------------------+-------------------------------------
Reporter: brycenesbitt | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: GIS | Version: 1.8
Severity: Normal | Resolution:
Keywords: PostGIS, GeoDjango, | Triage Stage:
GIS, Usability | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by brycenesbitt):
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Old description:
> 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 '
>
> }}}
New description:
For a project with GeoDjango if 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 '
}}}
--
--
Ticket URL: <https://code.djangoproject.com/ticket/24862#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/070.9cc6024e7382a17c34f199a597790115%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.