mirror of
https://github.com/django/django.git
synced 2025-07-19 00:59:17 +00:00
[1.0.X] Fixed #10839 -- GeoQuery
now unpickles properly on Oracle.
Backport of r10615 from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@10616 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
f110f91a03
commit
725ffa57bb
@ -30,6 +30,13 @@ class GeoQuery(sql.Query):
|
|||||||
self.transformed_srid = None
|
self.transformed_srid = None
|
||||||
self.extra_select_fields = {}
|
self.extra_select_fields = {}
|
||||||
|
|
||||||
|
if SpatialBackend.oracle:
|
||||||
|
# Have to override this so that GeoQuery, instead of OracleQuery,
|
||||||
|
# is returned when unpickling.
|
||||||
|
def __reduce__(self):
|
||||||
|
callable, args, data = super(GeoQuery, self).__reduce__()
|
||||||
|
return (unpickle_geoquery, (), data)
|
||||||
|
|
||||||
def clone(self, *args, **kwargs):
|
def clone(self, *args, **kwargs):
|
||||||
obj = super(GeoQuery, self).clone(*args, **kwargs)
|
obj = super(GeoQuery, self).clone(*args, **kwargs)
|
||||||
# Customized selection dictionary and transformed srid flag have
|
# Customized selection dictionary and transformed srid flag have
|
||||||
@ -324,6 +331,15 @@ class GeoQuery(sql.Query):
|
|||||||
# a lookup to a _related_ geographic field.
|
# a lookup to a _related_ geographic field.
|
||||||
return self._check_geo_field(self.model, field_name)
|
return self._check_geo_field(self.model, field_name)
|
||||||
|
|
||||||
|
if SpatialBackend.oracle:
|
||||||
|
def unpickle_geoquery():
|
||||||
|
"""
|
||||||
|
Utility function, called by Python's unpickling machinery, that handles
|
||||||
|
unpickling of GeoQuery subclasses of OracleQuery.
|
||||||
|
"""
|
||||||
|
return GeoQuery.__new__(GeoQuery)
|
||||||
|
unpickle_geoquery.__safe_for_unpickling__ = True
|
||||||
|
|
||||||
### Field Classes for `convert_values` ####
|
### Field Classes for `convert_values` ####
|
||||||
class BaseField(object):
|
class BaseField(object):
|
||||||
def get_internal_type(self):
|
def get_internal_type(self):
|
||||||
|
@ -137,6 +137,15 @@ class RelatedGeoModelTest(unittest.TestCase):
|
|||||||
self.assertEqual(val_dict['id'], c_id)
|
self.assertEqual(val_dict['id'], c_id)
|
||||||
self.assertEqual(val_dict['location__id'], l_id)
|
self.assertEqual(val_dict['location__id'], l_id)
|
||||||
|
|
||||||
|
def test11_geoquery_pickle(self):
|
||||||
|
"Ensuring GeoQuery objects are unpickled correctly. See #10839."
|
||||||
|
import pickle
|
||||||
|
from django.contrib.gis.db.models.sql import GeoQuery
|
||||||
|
qs = City.objects.all()
|
||||||
|
q_str = pickle.dumps(qs.query)
|
||||||
|
q = pickle.loads(q_str)
|
||||||
|
self.assertEqual(GeoQuery, q.__class__)
|
||||||
|
|
||||||
# TODO: Related tests for KML, GML, and distance lookups.
|
# TODO: Related tests for KML, GML, and distance lookups.
|
||||||
|
|
||||||
def suite():
|
def suite():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user