Author: carljm Date: 2012-03-02 14:32:22 -0800 (Fri, 02 Mar 2012) New Revision: 17632
Added: django/trunk/django/contrib/gis/db/backends/mysql/compiler.py Modified: django/trunk/django/contrib/gis/db/backends/mysql/operations.py django/trunk/django/contrib/gis/tests/geoapp/models.py django/trunk/django/contrib/gis/tests/geoapp/test_regress.py Log: Fixed #15169 -- Added conversion of 0/1 to False/True for MySQL GIS backend. Thanks zmsmith for report, and Ramiro for draft patch and review. Added: django/trunk/django/contrib/gis/db/backends/mysql/compiler.py =================================================================== --- django/trunk/django/contrib/gis/db/backends/mysql/compiler.py (rev 0) +++ django/trunk/django/contrib/gis/db/backends/mysql/compiler.py 2012-03-02 22:32:22 UTC (rev 17632) @@ -0,0 +1,32 @@ +from django.contrib.gis.db.models.sql.compiler import GeoSQLCompiler as BaseGeoSQLCompiler +from django.db.backends.mysql import compiler + +SQLCompiler = compiler.SQLCompiler + +class GeoSQLCompiler(BaseGeoSQLCompiler, SQLCompiler): + def resolve_columns(self, row, fields=()): + """ + Integrate the cases handled both by the base GeoSQLCompiler and the + main MySQL compiler (converting 0/1 to True/False for boolean fields). + + Refs #15169. + + """ + row = BaseGeoSQLCompiler.resolve_columns(self, row, fields) + return SQLCompiler.resolve_columns(self, row, fields) + + +class SQLInsertCompiler(compiler.SQLInsertCompiler, GeoSQLCompiler): + pass + +class SQLDeleteCompiler(compiler.SQLDeleteCompiler, GeoSQLCompiler): + pass + +class SQLUpdateCompiler(compiler.SQLUpdateCompiler, GeoSQLCompiler): + pass + +class SQLAggregateCompiler(compiler.SQLAggregateCompiler, GeoSQLCompiler): + pass + +class SQLDateCompiler(compiler.SQLDateCompiler, GeoSQLCompiler): + pass Modified: django/trunk/django/contrib/gis/db/backends/mysql/operations.py =================================================================== --- django/trunk/django/contrib/gis/db/backends/mysql/operations.py 2012-03-02 20:34:46 UTC (rev 17631) +++ django/trunk/django/contrib/gis/db/backends/mysql/operations.py 2012-03-02 22:32:22 UTC (rev 17632) @@ -5,7 +5,7 @@ class MySQLOperations(DatabaseOperations, BaseSpatialOperations): - compiler_module = 'django.contrib.gis.db.models.sql.compiler' + compiler_module = 'django.contrib.gis.db.backends.mysql.compiler' mysql = True name = 'mysql' select = 'AsText(%s)' Modified: django/trunk/django/contrib/gis/tests/geoapp/models.py =================================================================== --- django/trunk/django/contrib/gis/tests/geoapp/models.py 2012-03-02 20:34:46 UTC (rev 17631) +++ django/trunk/django/contrib/gis/tests/geoapp/models.py 2012-03-02 22:32:22 UTC (rev 17632) @@ -34,6 +34,10 @@ objects = models.GeoManager() def __unicode__(self): return self.name +class Truth(models.Model): + val = models.BooleanField() + objects = models.GeoManager() + if not spatialite: class Feature(models.Model): name = models.CharField(max_length=20) Modified: django/trunk/django/contrib/gis/tests/geoapp/test_regress.py =================================================================== --- django/trunk/django/contrib/gis/tests/geoapp/test_regress.py 2012-03-02 20:34:46 UTC (rev 17631) +++ django/trunk/django/contrib/gis/tests/geoapp/test_regress.py 2012-03-02 22:32:22 UTC (rev 17632) @@ -7,7 +7,7 @@ from django.db.models import Count from django.test import TestCase -from .models import City, PennsylvaniaCity, State +from .models import City, PennsylvaniaCity, State, Truth class GeoRegressionTests(TestCase): @@ -64,3 +64,17 @@ "Regression for #16409. Make sure defer() and only() work with annotate()" self.assertIsInstance(list(City.objects.annotate(Count('point')).defer('name')), list) self.assertIsInstance(list(City.objects.annotate(Count('point')).only('name')), list) + + def test07_boolean_conversion(self): + "Testing Boolean value conversion with the spatial backend, see #15169." + t1 = Truth.objects.create(val=True) + t2 = Truth.objects.create(val=False) + + val1 = Truth.objects.get(pk=1).val + val2 = Truth.objects.get(pk=2).val + # verify types -- should't be 0/1 + self.assertIsInstance(val1, bool) + self.assertIsInstance(val2, bool) + # verify values + self.assertEqual(val1, True) + self.assertEqual(val2, False) -- 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.