From 0d9e1163e897d8e43a3e018938a58131efcbc135 Mon Sep 17 00:00:00 2001 From: Nick Pope Date: Sun, 3 Sep 2017 23:00:07 +0100 Subject: [PATCH] Fixed #28569 -- Corrected get_layer_by_name prototype to skip error checking. All other get_*_by_name functions have errcheck=False. This makes it return None for an invalid name instead of raising a GDALException. --- django/contrib/gis/gdal/prototypes/ds.py | 2 +- tests/gis_tests/gdal_tests/test_ds.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/django/contrib/gis/gdal/prototypes/ds.py b/django/contrib/gis/gdal/prototypes/ds.py index 030d142c1c..e699654e49 100644 --- a/django/contrib/gis/gdal/prototypes/ds.py +++ b/django/contrib/gis/gdal/prototypes/ds.py @@ -28,7 +28,7 @@ destroy_ds = void_output(lgdal.OGR_DS_Destroy, [c_void_p], errcheck=False) release_ds = void_output(lgdal.OGRReleaseDataSource, [c_void_p]) get_ds_name = const_string_output(lgdal.OGR_DS_GetName, [c_void_p]) get_layer = voidptr_output(lgdal.OGR_DS_GetLayer, [c_void_p, c_int]) -get_layer_by_name = voidptr_output(lgdal.OGR_DS_GetLayerByName, [c_void_p, c_char_p]) +get_layer_by_name = voidptr_output(lgdal.OGR_DS_GetLayerByName, [c_void_p, c_char_p], errcheck=False) get_layer_count = int_output(lgdal.OGR_DS_GetLayerCount, [c_void_p]) # Layer Routines diff --git a/tests/gis_tests/gdal_tests/test_ds.py b/tests/gis_tests/gdal_tests/test_ds.py index b0ebcba840..0d936ee036 100644 --- a/tests/gis_tests/gdal_tests/test_ds.py +++ b/tests/gis_tests/gdal_tests/test_ds.py @@ -86,6 +86,9 @@ class DataSourceTest(unittest.TestCase): with self.assertRaises(IndexError): ds[len(ds)] + with self.assertRaises(IndexError): + ds['invalid'] + def test02_invalid_shp(self): "Testing invalid SHP files for the Data Source." for source in bad_ds: