The problem was caused by django.contrib.gis.db.backends.mysql backend. It has own backend implementation which returns booleans as integers (it was fixed for 'core' mysql backend in https://code.djangoproject.com/ticket/13293 )

I think it's a bug which will afect some users after upgrading to django 1.4 - in my opinion quite serious.

Any comments before creating a ticket?


On 24.02.2012 11:25, Tomasz Kloc wrote:
Ticket with change described below: https://code.djangoproject.com/ticket/17114

I've also found that since Django 1.2 (https://docs.djangoproject.com/en/dev/releases/1.2/#booleanfield-on-mysql) booleans in mysql backend should be returned as True/False, but i still get ints values.

In [7]: AuctionCategoryCustomField.objects.all()[0].enable_search_filter
Out[7]: 1

environment:
In [6]: sys.version
Out[6]: '2.6.6 (r266:84292, Dec 26 2010, 22:31:48) \n[GCC 4.4.5]'

In [7]: django.VERSION
Out[7]: (1, 3, 1, 'final', 0)

On 24.02.2012 11:00, Tomasz Kloc wrote:
Hello,

I've changed my database from postgresql to mysql. I have never used mysql in django projects before, so it was surprising to me when i saw 0/1 values instead of True/False in boolean fields. It wasn't an issue until i upgraded django from 1.3.1 to 1.4b. After that, all boolean fields in admin interface are checked (in edit mode). They are rendered as:

<input type="checkbox" id="id_checkbox_filter" value="0" name="checkbox_filter" checked="checked">

i've looked into forms.widgets.CheckboxInput in both django versions and noticed some logic changes when checking value:

(1.3.1)

    def __init__(self, attrs=None, check_test=bool):
        super(CheckboxInput, self).__init__(attrs)
        # check_test is a callable that takes a value and returns True
        # if the checkbox should be checked for that value.
        self.check_test = check_test

(1.4b)


    def __init__(self, attrs=None, check_test=None):
        super(CheckboxInput, self).__init__(attrs)
        # check_test is a callable that takes a value and returns True
        # if the checkbox should be checked for that value.
        if check_test is None:
self.check_test = lambda v: not (v is False or v is None or v == '')
        else:
            self.check_test = check_test

in this case "0" is treated as True.

Is this a bug?

regards,
tomasz kloc




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

Reply via email to