mirror of
https://github.com/django/django.git
synced 2024-12-23 01:25:58 +00:00
Fixed contrib.gis tests breaking in some edge cases.
The tests would error out with an ImproperlyConfigured error if the user had psycopg installed but not geos. Thanks to mcgohier for the report.
This commit is contained in:
parent
5b185ecc68
commit
a0d5970d44
@ -1,13 +1,25 @@
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.db import ProgrammingError
|
||||
from django.utils import six
|
||||
|
||||
try:
|
||||
from django.contrib.gis.db.backends.postgis.operations import PostGISOperations
|
||||
HAS_POSTGRES = True
|
||||
except ImportError:
|
||||
HAS_POSTGRES = False
|
||||
except ImproperlyConfigured as e:
|
||||
# If psycopg is installed but not geos, the import path hits
|
||||
# django.contrib.gis.geometry.backend which will "helpfully" convert
|
||||
# an ImportError into an ImproperlyConfigured.
|
||||
# Here, we make sure we're only catching this specific case and not another
|
||||
# ImproperlyConfigured one.
|
||||
if e.args and e.args[0].startswith('Could not import user-defined GEOMETRY_BACKEND'):
|
||||
HAS_POSTGRES = False
|
||||
else:
|
||||
six.reraise(*sys.exc_info())
|
||||
|
||||
|
||||
if HAS_POSTGRES:
|
||||
|
Loading…
Reference in New Issue
Block a user