Author: jbronn
Date: 2009-04-21 17:35:04 -0500 (Tue, 21 Apr 2009)
New Revision: 10615

Modified:
   django/trunk/django/contrib/gis/db/models/sql/query.py
   django/trunk/django/contrib/gis/tests/relatedapp/tests.py
Log:
Fixed #10839 -- `GeoQuery` now unpickles properly on Oracle.


Modified: django/trunk/django/contrib/gis/db/models/sql/query.py
===================================================================
--- django/trunk/django/contrib/gis/db/models/sql/query.py      2009-04-21 
21:25:47 UTC (rev 10614)
+++ django/trunk/django/contrib/gis/db/models/sql/query.py      2009-04-21 
22:35:04 UTC (rev 10615)
@@ -33,6 +33,13 @@
         self.transformed_srid = None
         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):
         obj = super(GeoQuery, self).clone(*args, **kwargs)
         # Customized selection dictionary and transformed srid flag have
@@ -332,3 +339,12 @@
             # Otherwise, check by the given field name -- which may be
             # a lookup to a _related_ geographic field.
             return GeoWhereNode._check_geo_field(self.model._meta, 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

Modified: django/trunk/django/contrib/gis/tests/relatedapp/tests.py
===================================================================
--- django/trunk/django/contrib/gis/tests/relatedapp/tests.py   2009-04-21 
21:25:47 UTC (rev 10614)
+++ django/trunk/django/contrib/gis/tests/relatedapp/tests.py   2009-04-21 
22:35:04 UTC (rev 10615)
@@ -222,6 +222,15 @@
         self.failUnless('Aurora' in names)
         self.failUnless('Kecksburg' in names)
 
+    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.
 
 def suite():


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to