Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #17796 -- Rolled back [17588] because the fix for the original …

…relatively

corner case (boolean fields under MySQL spatial backend) had a wider scope with
potentially unintended consequences affecting the main MySQL backend and the
required changes wouldn't be appropiate at this point of the 1.4 development
cycle.

Refs #15169.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17603 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit ae640e5ea08809f56be20957895a61168dbfaeca 1 parent c471cfd
Ramiro Morales authored February 29, 2012
22  django/contrib/gis/db/backends/mysql/compiler.py
... ...
@@ -1,22 +0,0 @@
1  
-from django.contrib.gis.db.models.sql.compiler import GeoSQLCompiler as BaseGeoSQLCompiler
2  
-from django.db.backends.mysql import compiler
3  
-
4  
-SQLCompiler = compiler.SQLCompiler
5  
-
6  
-class GeoSQLCompiler(BaseGeoSQLCompiler, SQLCompiler):
7  
-    pass
8  
-
9  
-class SQLInsertCompiler(compiler.SQLInsertCompiler, GeoSQLCompiler):
10  
-    pass
11  
-
12  
-class SQLDeleteCompiler(compiler.SQLDeleteCompiler, GeoSQLCompiler):
13  
-    pass
14  
-
15  
-class SQLUpdateCompiler(compiler.SQLUpdateCompiler, GeoSQLCompiler):
16  
-    pass
17  
-
18  
-class SQLAggregateCompiler(compiler.SQLAggregateCompiler, GeoSQLCompiler):
19  
-    pass
20  
-
21  
-class SQLDateCompiler(compiler.SQLDateCompiler, GeoSQLCompiler):
22  
-    pass
2  django/contrib/gis/db/backends/mysql/operations.py
@@ -5,7 +5,7 @@
5 5
 
6 6
 class MySQLOperations(DatabaseOperations, BaseSpatialOperations):
7 7
 
8  
-    compiler_module = 'django.contrib.gis.db.backends.mysql.compiler'
  8
+    compiler_module = 'django.contrib.gis.db.models.sql.compiler'
9 9
     mysql = True
10 10
     name = 'mysql'
11 11
     select = 'AsText(%s)'
7  django/contrib/gis/db/models/sql/compiler.py
@@ -185,10 +185,9 @@ def resolve_columns(self, row, fields=()):
185 185
                                self.query.extra_select_fields.get(a, None),
186 186
                                self.connection)
187 187
                   for v, a in izip(row[rn_offset:index_start], aliases)]
188  
-
189  
-        if self.connection.ops.oracle or self.connection.ops.mysql or getattr(self.query, 'geo_values', False):
190  
-            # We resolve the rest of the columns if we're on MySQL, Oracle or
191  
-            # if the `geo_values` attribute is defined.
  188
+        if self.connection.ops.oracle or getattr(self.query, 'geo_values', False):
  189
+            # We resolve the rest of the columns if we're on Oracle or if
  190
+            # the `geo_values` attribute is defined.
192 191
             for value, field in map(None, row[index_start:], fields):
193 192
                 values.append(self.query.convert_values(value, field, self.connection))
194 193
         else:
4  django/contrib/gis/db/models/sql/query.py
@@ -56,8 +56,8 @@ def convert_values(self, value, field, connection):
56 56
         extra selection objects into Geometry and Distance objects.
57 57
         TODO: Make converted objects 'lazy' for less overhead.
58 58
         """
59  
-        if connection.ops.oracle or connection.ops.mysql:
60  
-            # On MySQL and Oracle, call their version of `convert_values` first.
  59
+        if connection.ops.oracle:
  60
+            # Running through Oracle's first.
61 61
             value = super(GeoQuery, self).convert_values(value, field or GeomField(), connection)
62 62
 
63 63
         if value is None:
4  django/contrib/gis/tests/geoapp/models.py
@@ -34,10 +34,6 @@ class Track(models.Model):
34 34
     objects = models.GeoManager()
35 35
     def __unicode__(self): return self.name
36 36
 
37  
-class Truth(models.Model):
38  
-    val = models.BooleanField()
39  
-    objects = models.GeoManager()
40  
-
41 37
 if not spatialite:
42 38
     class Feature(models.Model):
43 39
         name = models.CharField(max_length=20)
10  django/contrib/gis/tests/geoapp/test_regress.py
@@ -7,7 +7,7 @@
7 7
 from django.db.models import Count
8 8
 from django.test import TestCase
9 9
 
10  
-from .models import City, PennsylvaniaCity, State, Truth
  10
+from .models import City, PennsylvaniaCity, State
11 11
 
12 12
 
13 13
 class GeoRegressionTests(TestCase):
@@ -64,11 +64,3 @@ def test06_defer_or_only_with_annotate(self):
64 64
         "Regression for #16409 - make sure defer() and only() work with annotate()"
65 65
         self.assertIsInstance(list(City.objects.annotate(Count('point')).defer('name')), list)
66 66
         self.assertIsInstance(list(City.objects.annotate(Count('point')).only('name')), list)
67  
-
68  
-    def test04_boolean_conversion(self):
69  
-        "Testing Boolean value conversion with the spatial backend, see #15169."
70  
-        t1 = Truth.objects.create(val=True)
71  
-        t2 = Truth.objects.create(val=False)
72  
-
73  
-        self.assertTrue(Truth.objects.get(pk=1).val is True)
74  
-        self.assertTrue(Truth.objects.get(pk=2).val is False)
6  django/db/backends/mysql/base.py
@@ -190,12 +190,6 @@ def _can_introspect_foreign_keys(self):
190 190
 class DatabaseOperations(BaseDatabaseOperations):
191 191
     compiler_module = "django.db.backends.mysql.compiler"
192 192
 
193  
-    def convert_values(self, value, field):
194  
-        if (field and field.get_internal_type() in ("BooleanField", "NullBooleanField") and
195  
-            value in (0, 1)):
196  
-            value = bool(value)
197  
-        return value
198  
-
199 193
     def date_extract_sql(self, lookup_type, field_name):
200 194
         # http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html
201 195
         if lookup_type == 'week_day':
5  django/db/backends/mysql/compiler.py
@@ -5,7 +5,10 @@ def resolve_columns(self, row, fields=()):
5 5
         values = []
6 6
         index_extra_select = len(self.query.extra_select.keys())
7 7
         for value, field in map(None, row[index_extra_select:], fields):
8  
-            values.append(self.query.convert_values(value, field, connection=self.connection))
  8
+            if (field and field.get_internal_type() in ("BooleanField", "NullBooleanField") and
  9
+                value in (0, 1)):
  10
+                value = bool(value)
  11
+            values.append(value)
9 12
         return row[:index_extra_select] + tuple(values)
10 13
 
11 14
 class SQLInsertCompiler(compiler.SQLInsertCompiler, SQLCompiler):

0 notes on commit ae640e5

Please sign in to comment.
Something went wrong with that request. Please try again.