The lack of boolean type coercion is more serious than it looks like at
first glance.
(starting from the example at http://code.djangoproject.com/ticket/7190)
In [1]: import django.newforms as forms
In [2]: from django.newforms.models import model_to_dict
In [3]: from simple.models import Simple
In [4]: simple_false = Simple.objects.create(b=False)
In [5]: simple_false_2 = Simple.objects.get(pk=simple_false.pk)
In [6]: class SimpleForm(forms.ModelForm):
...: b = forms.BooleanField(widget=forms.HiddenInput)
...: class Meta:
...: model = Simple
...:
In [7]: SimpleForm(data = model_to_dict(simple_false)).as_p()
Out[7]: u'<input type="hidden" name="b" value="False" id="id_b" />'
In [8]: SimpleForm(data = model_to_dict(simple_false_2)).as_p()
Out[8]: u'<input type="hidden" name="b" value="0" id="id_b" />'
When you POST the Out[8] form the value becomes bool("0") = True.
So when you save simple_false_2 based on the form the value is inverted
from False
to True.
Seems like a critical error...
The mysql.patch solves this issue too.
Pim.
Michael Glassford wrote:
> Your patch works, thanks. Perhaps you could add it to
> http://code.djangoproject.com/ticket/7190; I tried the patch there, but
> it doesn't work in this case.
>
> Mike
>
>
> Pim Van Heuven wrote:
>
>> Hi Michael,
>>
>> Can you apply this patch and run the tests again?
>> I have been running Django with this patch for a long time but never
>> got around to submitting it.
>>
>> Pim.
>>
>>
>>
>> Michael Glassford wrote:
>>
>>> I'm still trying to run the Django unit tests for the first time. I've
>>> worked through most of the errors--all of them so far proved to be
>>> caused by the MySQL/InnoDB ordering problem when deserializing objects
>>> that I asked about in another thread. However, I have one more set of
>>> errors that appear to have a different cause: it appears that, at least
>>> when fetching values using Model.objects.values(), a BooleanField isn't
>>> converting the value 1 to True. Is this a familiar problem? Hopefully it
>>> won't be another MySQL limitation!
>>>
>>> The errors are below:
>>>
>>>
>>>
>>>
>>>> $ python runtests.py --settings=django_regression_settings
>>>> model_inheritance_regress
>>>> ======================================================================
>>>> FAIL: Doctest:
>>>> regressiontests.model_inheritance_regress.models.__test__.API_TESTS
>>>> ----------------------------------------------------------------------
>>>> Traceback (most recent call last):
>>>> File
>>>> "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/test/_doctest.py",
>>>> line 2180, in runTest
>>>> raise self.failureException(self.format_failure(new.getvalue()))
>>>> AssertionError: Failed doctest test for
>>>> regressiontests.model_inheritance_regress.models.__test__.API_TESTS
>>>> File
>>>> "/develop/django/tests/regressiontests/model_inheritance_regress/models.py",
>>>> line unknown line number, in API_TESTS
>>>>
>>>> ----------------------------------------------------------------------
>>>> File
>>>> "/develop/django/tests/regressiontests/model_inheritance_regress/models.py",
>>>> line ?, in
>>>> regressiontests.model_inheritance_regress.models.__test__.API_TESTS
>>>> Failed example:
>>>> [sorted(d.items()) for d in dicts]
>>>> Expected:
>>>> [[('name', u"Guido's House of Pasta"), ('serves_hot_dogs', True)]]
>>>> Got:
>>>> [[('name', u"Guido's House of Pasta"), ('serves_hot_dogs', 1)]]
>>>> ----------------------------------------------------------------------
>>>> File
>>>> "/develop/django/tests/regressiontests/model_inheritance_regress/models.py",
>>>> line ?, in
>>>> regressiontests.model_inheritance_regress.models.__test__.API_TESTS
>>>> Failed example:
>>>> [sorted(d.items()) for d in dicts]
>>>> Expected:
>>>> [[('name', u"Guido's House of Pasta"), ('serves_gnocchi', True),
>>>> ('serves_hot_dogs', True)]]
>>>> Got:
>>>> [[('name', u"Guido's House of Pasta"), ('serves_gnocchi', 1),
>>>> ('serves_hot_dogs', 1)]]
>>>> ----------------------------------------------------------------------
>>>> File
>>>> "/develop/django/tests/regressiontests/model_inheritance_regress/models.py",
>>>> line ?, in
>>>> regressiontests.model_inheritance_regress.models.__test__.API_TESTS
>>>> Failed example:
>>>> [sorted(d.items()) for d in dicts]
>>>> Expected:
>>>> [[('name', u"Guido's All New House of Pasta"), ('serves_hot_dogs',
>>>> False)]]
>>>> Got:
>>>> [[('name', u"Guido's All New House of Pasta"), ('serves_hot_dogs', 0)]]
>>>> ----------------------------------------------------------------------
>>>> File
>>>> "/develop/django/tests/regressiontests/model_inheritance_regress/models.py",
>>>> line ?, in
>>>> regressiontests.model_inheritance_regress.models.__test__.API_TESTS
>>>> Failed example:
>>>> [sorted(d.items()) for d in dicts]
>>>> Expected:
>>>> [[('name', u"Guido's All New House of Pasta"), ('serves_gnocchi',
>>>> False), ('serves_hot_dogs', False)]]
>>>> Got:
>>>> [[('name', u"Guido's All New House of Pasta"), ('serves_gnocchi', 0),
>>>> ('serves_hot_dogs', 0)]]
>>>> ----------------------------------------------------------------------
>>>> File
>>>> "/develop/django/tests/regressiontests/model_inheritance_regress/models.py",
>>>> line ?, in
>>>> regressiontests.model_inheritance_regress.models.__test__.API_TESTS
>>>> Failed example:
>>>> [sorted(d.items()) for d in dicts]
>>>> Expected:
>>>> [[('name', u"Guido's All New House of Pasta"), ('serves_gnocchi',
>>>> False), ('serves_hot_dogs', False)]]
>>>> Got:
>>>> [[('name', u"Guido's All New House of Pasta"), ('serves_gnocchi', 0),
>>>> ('serves_hot_dogs', 0)]]
>>>>
>>>>
>>>> ----------------------------------------------------------------------
>>>> Ran 1 test in 0.057s
>>>>
>>>>
>>> Mike
>>>
>>>
>>>
>>>
>>>
>>>
>>
>
>
> >
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---