diff options
| author | Claude Paroz <claude@2xlibre.net> | 2014-06-28 16:05:13 +0200 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2014-06-28 16:18:24 +0200 |
| commit | f12b68af71efa0b061710c83364f231734d07e55 (patch) | |
| tree | 74c72ebd9bfb7b6648d355971d1363d7f180a22d | |
| parent | 70576740b0bb5289873f5a9a9a4e1a26b2c330e5 (diff) | |
Fixed #16184 -- Fixed multiple PostGIS types introspection
Thanks radim.blazek@gmail.com for the report and initial patch.
Testing is tricky, as the failure condition is a bit of an edge
case. inspectapp.InspectDbTests should at least guarantee non
regression.
| -rw-r--r-- | django/contrib/gis/db/backends/postgis/introspection.py | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/django/contrib/gis/db/backends/postgis/introspection.py b/django/contrib/gis/db/backends/postgis/introspection.py index 412014bf44..ad8d1db999 100644 --- a/django/contrib/gis/db/backends/postgis/introspection.py +++ b/django/contrib/gis/db/backends/postgis/introspection.py @@ -25,23 +25,25 @@ class PostGISIntrospection(DatabaseIntrospection): identification integers for the PostGIS geometry and/or geography types (if supported). """ - cursor = self.connection.cursor() + field_types = [('geometry', 'GeometryField')] + if self.connection.ops.geography: + # The value for the geography type is actually a tuple + # to pass in the `geography=True` keyword to the field + # definition. + field_types.append(('geography', ('GeometryField', {'geography' : True}))) + postgis_types = {} + # The OID integers associated with the geometry type may # be different across versions; hence, this is why we have # to query the PostgreSQL pg_type table corresponding to the # PostGIS custom data types. oid_sql = 'SELECT "oid" FROM "pg_type" WHERE "typname" = %s' + cursor = self.connection.cursor() try: - cursor.execute(oid_sql, ('geometry',)) - GEOM_TYPE = cursor.fetchone()[0] - postgis_types = {GEOM_TYPE: 'GeometryField'} - if self.connection.ops.geography: - cursor.execute(oid_sql, ('geography',)) - GEOG_TYPE = cursor.fetchone()[0] - # The value for the geography type is actually a tuple - # to pass in the `geography=True` keyword to the field - # definition. - postgis_types[GEOG_TYPE] = ('GeometryField', {'geography': True}) + for field_type in field_types: + cursor.execute(oid_sql, (field_type[0],)) + for result in cursor.fetchall(): + postgis_types[result[0]] = field_type[1] finally: cursor.close() |
