diff --git a/django/contrib/gis/db/backends/oracle/operations.py b/django/contrib/gis/db/backends/oracle/operations.py index 3af78929f8..4beb5a1589 100644 --- a/django/contrib/gis/db/backends/oracle/operations.py +++ b/django/contrib/gis/db/backends/oracle/operations.py @@ -142,6 +142,17 @@ class OracleOperations(DatabaseOperations, BaseSpatialOperations): truncate_params = {'relate': None} + def get_db_converters(self, internal_type): + converters = super(OracleOperations, self).get_db_converters(internal_type) + geometry_fields = ( + 'PointField', 'GeometryField', 'LineStringField', + 'PolygonField', 'MultiPointField', 'MultiLineStringField', + 'MultiPolygonField', 'GeometryCollectionField', 'GeomField', + ) + if internal_type in geometry_fields: + converters.append(self.convert_textfield_value) + return converters + def convert_extent(self, clob): if clob: # Generally, Oracle returns a polygon for the extent -- however, diff --git a/django/contrib/gis/db/models/fields.py b/django/contrib/gis/db/models/fields.py index 2e0e13abf9..c79548ed8a 100644 --- a/django/contrib/gis/db/models/fields.py +++ b/django/contrib/gis/db/models/fields.py @@ -198,7 +198,7 @@ class GeometryField(Field): return geom def from_db_value(self, value, connection): - if value is not None: + if value: value = Geometry(value) return value diff --git a/django/contrib/gis/db/models/sql/compiler.py b/django/contrib/gis/db/models/sql/compiler.py index e721514085..05491ef930 100644 --- a/django/contrib/gis/db/models/sql/compiler.py +++ b/django/contrib/gis/db/models/sql/compiler.py @@ -152,7 +152,8 @@ class GeoSQLCompiler(compiler.SQLCompiler): for i, alias in enumerate(self.query.extra_select): field = self.query.extra_select_fields.get(alias) if field: - converters[i] = ([], [field.from_db_value], field) + backend_converters = self.connection.ops.get_db_converters(field.get_internal_type()) + converters[i] = (backend_converters, [field.from_db_value], field) return converters #### Routines unique to GeoQuery ####