Ticket #13293: 13293.patch

File 13293.patch, 2.2 KB (added by Matthias Kestenholz, 15 years ago)

Now with a regression test

  • django/db/backends/mysql/compiler.py

    diff --git a/django/db/backends/mysql/compiler.py b/django/db/backends/mysql/compiler.py
    index 07832f2..535bec4 100644
    a b from django.db.models.sql import compiler  
    33class SQLCompiler(compiler.SQLCompiler):
    44    def resolve_columns(self, row, fields=()):
    55        values = []
    6         for value, field in map(None, row, fields):
     6        index_extra_select = len(self.query.extra_select.keys())
     7        for value, field in map(None, row[index_extra_select:], fields):
    78            if (field and field.get_internal_type() in ("BooleanField", "NullBooleanField") and
    89                value in (0, 1)):
    910                value = bool(value)
    1011            values.append(value)
    11         return tuple(values)
     12        return tuple(values[:index_extra_select] + values)
    1213
    1314
    1415class SQLInsertCompiler(compiler.SQLInsertCompiler, SQLCompiler):
  • tests/regressiontests/model_fields/models.py

    diff --git a/tests/regressiontests/model_fields/models.py b/tests/regressiontests/model_fields/models.py
    index 5e480aa..72c7beb 100644
    a b class NullBooleanModel(models.Model):  
    6969
    7070class BooleanModel(models.Model):
    7171    bfield = models.BooleanField()
     72    string = models.CharField(max_length=10, default='abc')
    7273
    7374###############################################################################
    7475# ImageField
  • tests/regressiontests/model_fields/tests.py

    diff --git a/tests/regressiontests/model_fields/tests.py b/tests/regressiontests/model_fields/tests.py
    index 05b710d..cfb7d58 100644
    a b class BooleanFieldTests(unittest.TestCase):  
    191191        self.assertTrue(isinstance(b4.nbfield, bool))
    192192        self.assertEqual(b4.nbfield, False)
    193193
     194        # http://code.djangoproject.com/ticket/13293
     195        # Verify that extra select clauses are handled correctly
     196        b5 = BooleanModel.objects.all().extra(
     197            select={'string_length': 'LENGTH(string)'})[0]
     198        self.assertFalse(isinstance(b5.pk, bool))
     199
    194200class ChoicesTests(django.test.TestCase):
    195201    def test_choices_and_field_display(self):
    196202        """
Back to Top