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.
This commit is contained in:
parent
70576740b0
commit
f12b68af71
|
@ -25,23 +25,25 @@ class PostGISIntrospection(DatabaseIntrospection):
|
||||||
identification integers for the PostGIS geometry and/or
|
identification integers for the PostGIS geometry and/or
|
||||||
geography types (if supported).
|
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
|
# The OID integers associated with the geometry type may
|
||||||
# be different across versions; hence, this is why we have
|
# be different across versions; hence, this is why we have
|
||||||
# to query the PostgreSQL pg_type table corresponding to the
|
# to query the PostgreSQL pg_type table corresponding to the
|
||||||
# PostGIS custom data types.
|
# PostGIS custom data types.
|
||||||
oid_sql = 'SELECT "oid" FROM "pg_type" WHERE "typname" = %s'
|
oid_sql = 'SELECT "oid" FROM "pg_type" WHERE "typname" = %s'
|
||||||
|
cursor = self.connection.cursor()
|
||||||
try:
|
try:
|
||||||
cursor.execute(oid_sql, ('geometry',))
|
for field_type in field_types:
|
||||||
GEOM_TYPE = cursor.fetchone()[0]
|
cursor.execute(oid_sql, (field_type[0],))
|
||||||
postgis_types = {GEOM_TYPE: 'GeometryField'}
|
for result in cursor.fetchall():
|
||||||
if self.connection.ops.geography:
|
postgis_types[result[0]] = field_type[1]
|
||||||
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})
|
|
||||||
finally:
|
finally:
|
||||||
cursor.close()
|
cursor.close()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue