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
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)
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?
--
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.
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
I think there is one already:
https://code.djangoproject.com/ticket/15169
--
Ramiro Morales