summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Fedoseev <fedoseev.sergey@gmail.com>2018-07-09 20:02:12 +0500
committerTim Graham <timograham@gmail.com>2018-07-09 11:02:12 -0400
commit3411c5551aa4ec141eb214f2928db4b077b41dd3 (patch)
tree913a5f426863af662e2fb3de5a1a898a38c161a7
parentbdcde79c5f9b0fdacf509e3745e9911e4002025a (diff)
Refs #27472 -- Fixed crash during pickling of empty GEOS point.
-rw-r--r--django/contrib/gis/geos/geometry.py10
-rw-r--r--django/contrib/gis/geos/point.py6
-rw-r--r--tests/gis_tests/geos_tests/test_geos.py3
3 files changed, 16 insertions, 3 deletions
diff --git a/django/contrib/gis/geos/geometry.py b/django/contrib/gis/geos/geometry.py
index 777e465883..4b3779938e 100644
--- a/django/contrib/gis/geos/geometry.py
+++ b/django/contrib/gis/geos/geometry.py
@@ -87,15 +87,21 @@ class GEOSGeometryBase(GEOSBase):
return '<%s object at %s>' % (self.geom_type, hex(addressof(self.ptr)))
# Pickling support
+ def _to_pickle_wkb(self):
+ return bytes(self.wkb)
+
+ def _from_pickle_wkb(self, wkb):
+ return wkb_r().read(memoryview(wkb))
+
def __getstate__(self):
# The pickled state is simply a tuple of the WKB (in string form)
# and the SRID.
- return bytes(self.wkb), self.srid
+ return self._to_pickle_wkb(), self.srid
def __setstate__(self, state):
# Instantiating from the tuple state that was pickled.
wkb, srid = state
- ptr = wkb_r().read(memoryview(wkb))
+ ptr = self._from_pickle_wkb(wkb)
if not ptr:
raise GEOSException('Invalid Geometry loaded from pickled state.')
self.ptr = ptr
diff --git a/django/contrib/gis/geos/point.py b/django/contrib/gis/geos/point.py
index ccf5b9dbaf..24465f6324 100644
--- a/django/contrib/gis/geos/point.py
+++ b/django/contrib/gis/geos/point.py
@@ -40,6 +40,12 @@ class Point(GEOSGeometry):
# createPoint factory.
super().__init__(point, srid=srid)
+ def _to_pickle_wkb(self):
+ return None if self.empty else super()._to_pickle_wkb()
+
+ def _from_pickle_wkb(self, wkb):
+ return self._create_empty() if wkb is None else super()._from_pickle_wkb(wkb)
+
def _ogr_ptr(self):
return gdal.geometries.Point._create_empty() if self.empty else super()._ogr_ptr()
diff --git a/tests/gis_tests/geos_tests/test_geos.py b/tests/gis_tests/geos_tests/test_geos.py
index 5f8d1c84b1..1924ccb356 100644
--- a/tests/gis_tests/geos_tests/test_geos.py
+++ b/tests/gis_tests/geos_tests/test_geos.py
@@ -1181,7 +1181,8 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
tgeoms.extend(get_geoms(self.geometries.multilinestrings, 4326))
tgeoms.extend(get_geoms(self.geometries.polygons, 3084))
tgeoms.extend(get_geoms(self.geometries.multipolygons, 3857))
-
+ tgeoms.append(Point(srid=4326))
+ tgeoms.append(Point())
for geom in tgeoms:
s1 = pickle.dumps(geom)
g1 = pickle.loads(s1)