django 1.4b + mysql + boolean fields

119 views
Skip to first unread message

Tomasz Kloc

unread,
Feb 24, 2012, 5:00:44 AM2/24/12
to django-d...@googlegroups.com
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

Tomasz Kloc

unread,
Feb 24, 2012, 5:25:42 AM2/24/12
to django-d...@googlegroups.com
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)

Tomasz Kloc

unread,
Feb 24, 2012, 5:53:38 AM2/24/12
to django-d...@googlegroups.com
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?

Aymeric Augustin

unread,
Feb 24, 2012, 11:14:58 AM2/24/12
to django-d...@googlegroups.com
Please go ahead, create a ticket and set its severity to "release blocker".

Assuming a proper test was added with the fix for #13293, that test should fail on the geographic version of mysql. Unfortunately we don't have this engine on the CI server at this time. I'll try to add it.

Thanks for your feedback,

-- 
Aymeric.


2012/2/24 Tomasz Kloc <tomek.k...@gmail.com>
--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.



Carl Meyer

unread,
Feb 24, 2012, 11:25:44 AM2/24/12
to django-d...@googlegroups.com
Hello Tomasz,

On 02/24/2012 03:00 AM, Tomasz Kloc wrote:
> 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).

If I am not mistaken, this was already reported in ticket #17747
(https://code.djangoproject.com/ticket/17747). It had been closed as
"worksforme" because the original reporter didn't realize the problem
was specifically related to use of MySQL (and, it seems, the MySQL GIS
backend). Thanks for the additional information!

Carl

signature.asc

Aymeric Augustin

unread,
Feb 24, 2012, 11:19:26 AM2/24/12
to django-d...@googlegroups.com
I just noticed that #17747 was reopened for this purpose, so there's no need for another ticket.

Best regards,

-- 
Aymeric.

2012/2/24 Aymeric Augustin <aymeric....@polytechnique.org>



--
Aymeric.

Ramiro Morales

unread,
Feb 24, 2012, 11:20:29 AM2/24/12
to django-d...@googlegroups.com
On Fri, Feb 24, 2012 at 7:53 AM, Tomasz Kloc <tomek.k...@gmail.com> wrote:
> 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?

I think there is one already:

https://code.djangoproject.com/ticket/15169

--
Ramiro Morales

Reply all
Reply to author
Forward
0 new messages