diff --git a/django/contrib/gis/tests/data/invalid/emptypoints.dbf b/django/contrib/gis/tests/data/invalid/emptypoints.dbf
new file mode 100644
index 0000000000000000000000000000000000000000..aa2109047a4f7b5d4f7fdc372c065148aff5f8c7
GIT binary patch
literal 77
mc${O7XP07RU|?`$;9<Z3;S3CJo-Qz+ABf;aQ^Ko&00sbtl>_ns
diff --git a/django/contrib/gis/tests/data/invalid/emptypoints.shp b/django/contrib/gis/tests/data/invalid/emptypoints.shp
new file mode 100644
index 0000000000000000000000000000000000000000..bdcfb83be42f71ecb07c7d395f4c40e13e6cde16
GIT binary patch
literal 112
cc${NkQ0HR64lG_UGcYjXkR%a+j9~&X0Ck7~SpWb4
diff --git a/django/contrib/gis/tests/data/invalid/emptypoints.shx b/django/contrib/gis/tests/data/invalid/emptypoints.shx
new file mode 100644
index 0000000000000000000000000000000000000000..dea663eb087d4a778415da28a9ee226864363515
GIT binary patch
literal 108
bc${NkQ0HR64$NLKGcYjXkR%Zp0WlK*aCZTS
diff --git a/django/contrib/gis/tests/layermap/models.py b/django/contrib/gis/tests/layermap/models.py
a
|
b
|
|
43 | 43 | class ICity2(ICity1): |
44 | 44 | dt_time = models.DateTimeField(auto_now=True) |
45 | 45 | |
| 46 | class Invalid(models.Model): |
| 47 | point = models.PointField() |
| 48 | |
46 | 49 | # Mapping dictionaries for the models above. |
47 | 50 | co_mapping = {'name' : 'Name', |
48 | 51 | 'state' : {'name' : 'State'}, # ForeignKey's use another mapping dictionary for the _related_ Model (State in this case). |
diff --git a/django/contrib/gis/tests/layermap/tests.py b/django/contrib/gis/tests/layermap/tests.py
a
|
b
|
|
4 | 4 | from django.utils.copycompat import copy |
5 | 5 | from django.utils.unittest import TestCase |
6 | 6 | |
7 | | from django.contrib.gis.gdal import DataSource |
| 7 | from django.contrib.gis.gdal import DataSource, OGRException |
8 | 8 | from django.contrib.gis.tests.utils import mysql |
9 | 9 | from django.contrib.gis.utils.layermapping import LayerMapping, LayerMapError, InvalidDecimal, MissingForeignKey |
10 | 10 | |
11 | | from models import City, County, CountyFeat, Interstate, ICity1, ICity2, State, city_mapping, co_mapping, cofeat_mapping, inter_mapping |
| 11 | from models import \ |
| 12 | City, County, CountyFeat, Interstate, ICity1, ICity2, Invalid, State, \ |
| 13 | city_mapping, co_mapping, cofeat_mapping, inter_mapping |
12 | 14 | |
13 | 15 | shp_path = os.path.realpath(os.path.join(os.path.dirname(__file__), os.pardir, 'data')) |
14 | 16 | city_shp = os.path.join(shp_path, 'cities', 'cities.shp') |
15 | 17 | co_shp = os.path.join(shp_path, 'counties', 'counties.shp') |
16 | 18 | inter_shp = os.path.join(shp_path, 'interstates', 'interstates.shp') |
| 19 | invalid_shp = os.path.join(shp_path, 'invalid', 'emptypoints.shp') |
17 | 20 | |
18 | 21 | # Dictionaries to hold what's expected in the county shapefile. |
19 | 22 | NAMES = ['Bexar', 'Galveston', 'Harris', 'Honolulu', 'Pueblo'] |
… |
… |
|
265 | 268 | |
266 | 269 | self.assertEqual(6, ICity1.objects.count()) |
267 | 270 | self.assertEqual(3, ICity2.objects.count()) |
| 271 | |
| 272 | def test07_invalid_layer(self): |
| 273 | "Tests LayerMapping on invalid geometries. See #15378." |
| 274 | invalid_mapping = {'point': 'POINT'} |
| 275 | lm = LayerMapping(Invalid, invalid_shp, invalid_mapping, |
| 276 | source_srs=4326) |
| 277 | lm.save(silent=True) |
diff --git a/django/contrib/gis/utils/layermapping.py b/django/contrib/gis/utils/layermapping.py
a
|
b
|
|
294 | 294 | |
295 | 295 | if isinstance(model_field, GeometryField): |
296 | 296 | # Verify OGR geometry. |
297 | | val = self.verify_geom(feat.geom, model_field) |
| 297 | try: |
| 298 | val = self.verify_geom(feat.geom, model_field) |
| 299 | except OGRException: |
| 300 | raise LayerMapError('Could not retrieve geometry from feature.') |
298 | 301 | elif isinstance(model_field, models.base.ModelBase): |
299 | 302 | # The related _model_, not a field was passed in -- indicating |
300 | 303 | # another mapping for the related Model. |