Fixed #31162 -- Prevented error logs when using WKT strings in lookups.
Thanks dbxnr for the initial patch.
Regression in 6f44f714c9
.
This commit is contained in:
parent
d08d4f464a
commit
266c853e10
|
@ -73,6 +73,13 @@ class GDALRaster(GDALRasterBase):
|
||||||
|
|
||||||
# If input is a valid file path, try setting file as source.
|
# If input is a valid file path, try setting file as source.
|
||||||
if isinstance(ds_input, str):
|
if isinstance(ds_input, str):
|
||||||
|
if (
|
||||||
|
not ds_input.startswith(VSI_FILESYSTEM_BASE_PATH) and
|
||||||
|
not os.path.exists(ds_input)
|
||||||
|
):
|
||||||
|
raise GDALException(
|
||||||
|
'Unable to read raster source input "%s".' % ds_input
|
||||||
|
)
|
||||||
try:
|
try:
|
||||||
# GDALOpen will auto-detect the data source type.
|
# GDALOpen will auto-detect the data source type.
|
||||||
self._ptr = capi.open_ds(force_bytes(ds_input), self._write)
|
self._ptr = capi.open_ds(force_bytes(ds_input), self._write)
|
||||||
|
@ -225,7 +232,7 @@ class GDALRaster(GDALRasterBase):
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def is_vsi_based(self):
|
def is_vsi_based(self):
|
||||||
return self.name.startswith(VSI_FILESYSTEM_BASE_PATH)
|
return self._ptr and self.name.startswith(VSI_FILESYSTEM_BASE_PATH)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
|
|
|
@ -156,6 +156,11 @@ class GDALRasterTests(SimpleTestCase):
|
||||||
else:
|
else:
|
||||||
self.assertEqual(restored_raster.bands[0].data(), self.rs.bands[0].data())
|
self.assertEqual(restored_raster.bands[0].data(), self.rs.bands[0].data())
|
||||||
|
|
||||||
|
def test_nonexistent_file(self):
|
||||||
|
msg = 'Unable to read raster source input "nonexistent.tif".'
|
||||||
|
with self.assertRaisesMessage(GDALException, msg):
|
||||||
|
GDALRaster('nonexistent.tif')
|
||||||
|
|
||||||
def test_vsi_raster_creation(self):
|
def test_vsi_raster_creation(self):
|
||||||
# Open a raster as a file object.
|
# Open a raster as a file object.
|
||||||
with open(self.rs_path, 'rb') as dat:
|
with open(self.rs_path, 'rb') as dat:
|
||||||
|
|
|
@ -430,6 +430,12 @@ class GeoLookupTest(TestCase):
|
||||||
with self.subTest(lookup=lookup):
|
with self.subTest(lookup=lookup):
|
||||||
self.assertNotIn(null, State.objects.filter(**{'poly__%s' % lookup: geom}))
|
self.assertNotIn(null, State.objects.filter(**{'poly__%s' % lookup: geom}))
|
||||||
|
|
||||||
|
def test_wkt_string_in_lookup(self):
|
||||||
|
# Valid WKT strings don't emit error logs.
|
||||||
|
with self.assertRaisesMessage(AssertionError, 'no logs'):
|
||||||
|
with self.assertLogs('django.contrib.gis', 'ERROR'):
|
||||||
|
State.objects.filter(poly__intersects='LINESTRING(0 0, 1 1, 5 5)')
|
||||||
|
|
||||||
@skipUnlessDBFeature("supports_relate_lookup")
|
@skipUnlessDBFeature("supports_relate_lookup")
|
||||||
def test_relate_lookup(self):
|
def test_relate_lookup(self):
|
||||||
"Testing the 'relate' lookup type."
|
"Testing the 'relate' lookup type."
|
||||||
|
|
Loading…
Reference in New Issue