From b0f869891c7b310d7f0f60af8e87e3fc45cd11e2 Mon Sep 17 00:00:00 2001 From: David Smith Date: Thu, 11 Jan 2024 18:29:38 +0000 Subject: [PATCH] Fixed LayerMapping with Oracle 23c. Oracle 23c collapses MULTI geometries with only one entry to their non-MULTI type. Added check when loading geometries from the database that a MULTI type is returned. Reconvert to correct geometry type, if required. --- django/contrib/gis/utils/layermapping.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/django/contrib/gis/utils/layermapping.py b/django/contrib/gis/utils/layermapping.py index 2dcf839603..74daa119b5 100644 --- a/django/contrib/gis/utils/layermapping.py +++ b/django/contrib/gis/utils/layermapping.py @@ -646,6 +646,14 @@ class LayerMapping: else: geom = geom_value.ogr new = OGRGeometry(kwargs[self.geom_field]) + if ( + geom_typeid := geom.geos.geom_typeid + ) in self.MULTI_TYPES: + # Database returned non-MULTI type, reconvert. + multi_type = self.MULTI_TYPES[geom_typeid] + g = OGRGeometry(multi_type) + g.add(geom) + geom = g for g in new: geom.add(g) setattr(m, self.geom_field, geom.wkt)