[Django] #24862: Patch for GeoDjango to improve error message if database connection is bad

17 views
Skip to first unread message

Django

unread,
May 27, 2015, 1:11:19 AM5/27/15
to django-...@googlegroups.com
#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 | Keywords: PostGIS, GeoDjango,
| GIS, Usability
Triage Stage: Unreviewed | Has patch: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
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 '

}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24862>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 27, 2015, 1:13:29 AM5/27/15
to django-...@googlegroups.com
#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:

New description:

For a project with GeoDjango if the database is completely down, you'll
get exception:

}}}

--

--
Ticket URL: <https://code.djangoproject.com/ticket/24862#comment:1>

Django

unread,
May 27, 2015, 3:09:37 AM5/27/15
to django-...@googlegroups.com
#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: master
Severity: Normal | Resolution:
Keywords: PostGIS, GeoDjango, | Triage Stage: Accepted
GIS, Usability |

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by claudep):

* needs_better_patch: 0 => 1
* version: 1.8 => master
* stage: Unreviewed => Accepted


Comment:

Good suggestion. Could you attach a patch against master, either as a
Github pull request, or as a `git diff` output?

--
Ticket URL: <https://code.djangoproject.com/ticket/24862#comment:2>

Django

unread,
Jun 5, 2015, 5:14:48 AM6/5/15
to django-...@googlegroups.com
#24862: Patch for GeoDjango to improve error message if database connection is bad
-------------------------------------+-------------------------------------
Reporter: brycenesbitt | Owner: sephii
Type: | Status: assigned

Cleanup/optimization |
Component: GIS | Version: master
Severity: Normal | Resolution:
Keywords: PostGIS, GeoDjango, | Triage Stage: Accepted
GIS, Usability |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by sephii):

* status: new => assigned
* owner: nobody => sephii


--
Ticket URL: <https://code.djangoproject.com/ticket/24862#comment:3>

Django

unread,
Jun 5, 2015, 6:59:38 AM6/5/15
to django-...@googlegroups.com
#24862: Patch for GeoDjango to improve error message if database connection is bad
-------------------------------------+-------------------------------------
Reporter: brycenesbitt | Owner: sephii
Type: | Status: assigned
Cleanup/optimization |
Component: GIS | Version: master
Severity: Normal | Resolution:
Keywords: PostGIS, GeoDjango, | Triage Stage: Accepted
GIS, Usability |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by sephii):

Pull request is available here:
https://github.com/django/django/pull/4796/

Note that:
* I didn't include tests for this trivial change
* I wasn't able to reproduce the issue since it looks like that on newer
PostGIS versions PostGIS functions are always available

--
Ticket URL: <https://code.djangoproject.com/ticket/24862#comment:4>

Django

unread,
Jun 5, 2015, 3:59:13 PM6/5/15
to django-...@googlegroups.com
#24862: Patch for GeoDjango to improve error message if database connection is bad
-------------------------------------+-------------------------------------
Reporter: brycenesbitt | Owner: sephii
Type: | Status: closed

Cleanup/optimization |
Component: GIS | Version: master
Severity: Normal | Resolution: fixed

Keywords: PostGIS, GeoDjango, | Triage Stage: Accepted
GIS, Usability |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Claude Paroz <claude@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"0a899157836cc4c3d3980ab6a70b2f37bbb7ba97" 0a899157]:
{{{
#!CommitTicketReference repository=""
revision="0a899157836cc4c3d3980ab6a70b2f37bbb7ba97"
Fixed #24862 -- Improved PostGIS database connection error message

Thanks brycenesbitt for the patch.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24862#comment:5>

Reply all
Reply to author
Forward
0 new messages