Fixed #28659 -- Fixed LayerMapping crash with null geometry and unique.
This commit is contained in:
parent
c72dde41e6
commit
e7a56eb4f0
|
@ -558,7 +558,11 @@ class LayerMapping:
|
||||||
# one from the kwargs WKT, adding in additional
|
# one from the kwargs WKT, adding in additional
|
||||||
# geometries, and update the attribute with the
|
# geometries, and update the attribute with the
|
||||||
# just-updated geometry WKT.
|
# just-updated geometry WKT.
|
||||||
geom = getattr(m, self.geom_field).ogr
|
geom_value = getattr(m, self.geom_field)
|
||||||
|
if geom_value is None:
|
||||||
|
geom = OGRGeometry(kwargs[self.geom_field])
|
||||||
|
else:
|
||||||
|
geom = geom_value.ogr
|
||||||
new = OGRGeometry(kwargs[self.geom_field])
|
new = OGRGeometry(kwargs[self.geom_field])
|
||||||
for g in new:
|
for g in new:
|
||||||
geom.add(g)
|
geom.add(g)
|
||||||
|
|
|
@ -17,7 +17,7 @@ class State(NamedModel):
|
||||||
|
|
||||||
class County(NamedModel):
|
class County(NamedModel):
|
||||||
state = models.ForeignKey(State, models.CASCADE)
|
state = models.ForeignKey(State, models.CASCADE)
|
||||||
mpoly = models.MultiPolygonField(srid=4269) # Multipolygon in NAD83
|
mpoly = models.MultiPolygonField(srid=4269, null=True) # Multipolygon in NAD83
|
||||||
|
|
||||||
|
|
||||||
class CountyFeat(NamedModel):
|
class CountyFeat(NamedModel):
|
||||||
|
|
|
@ -310,6 +310,17 @@ class LayerMapTest(TestCase):
|
||||||
self.assertEqual(City.objects.count(), 1)
|
self.assertEqual(City.objects.count(), 1)
|
||||||
self.assertEqual(City.objects.all()[0].name, "Zürich")
|
self.assertEqual(City.objects.all()[0].name, "Zürich")
|
||||||
|
|
||||||
|
def test_null_geom_with_unique(self):
|
||||||
|
"""LayerMapping may be created with a unique and a null geometry."""
|
||||||
|
State.objects.bulk_create([State(name='Colorado'), State(name='Hawaii'), State(name='Texas')])
|
||||||
|
hw = State.objects.get(name='Hawaii')
|
||||||
|
hu = County.objects.create(name='Honolulu', state=hw, mpoly=None)
|
||||||
|
lm = LayerMapping(County, co_shp, co_mapping, transform=False, unique='name')
|
||||||
|
lm.save(silent=True, strict=True)
|
||||||
|
hu.refresh_from_db()
|
||||||
|
self.assertIsNotNone(hu.mpoly)
|
||||||
|
self.assertEqual(hu.mpoly.ogr.num_coords, 449)
|
||||||
|
|
||||||
|
|
||||||
class OtherRouter:
|
class OtherRouter:
|
||||||
def db_for_read(self, model, **hints):
|
def db_for_read(self, model, **hints):
|
||||||
|
|
Loading…
Reference in New Issue