Hmm..

In my opinion, Model.full_clean() should catch this particular error.





On 1 June 2012 16:17, Kurtis Mullins <[email protected]> wrote:

> It looks like the CharField is accepting 'none' in its to_python method.
> That might explain why we don't get the error until your to save it. I'm
> sure there is a reason behind this -- I just don't know what it is :)
> Source: django/db/models/fields/__init__.py
>
>
> On Fri, Jun 1, 2012 at 11:08 AM, Kurtis Mullins 
> <[email protected]>wrote:
>
>> Yeah, I'm getting exactly the same results. It seems that it's not
>> throwing the IntegrityError until you try to save it. I suppose that's
>> because it's marked as 'not null' in the database. It appears to be
>> ignoring it in the actual clean() (and consequently clean_fields())
>> methods. I'm going to look into the source of the Model module and see
>> what's going on
>>
>>
>> On Fri, Jun 1, 2012 at 10:55 AM, David Markey <[email protected]> wrote:
>>
>>> 1.4
>>>
>>> On 1 June 2012 15:54, Kurtis Mullins <[email protected]> wrote:
>>>
>>>> What version of Django are you using?
>>>>
>>>>
>>>> On Fri, Jun 1, 2012 at 10:47 AM, David Markey <[email protected]>wrote:
>>>>
>>>>> That is my exact class for that model.
>>>>>
>>>>>
>>>>> On 1 June 2012 15:27, Kurtis Mullins <[email protected]> wrote:
>>>>>
>>>>>> From the docs:
>>>>>> https://docs.djangoproject.com/en/dev/ref/models/instances/?from=olddocs#django.db.models.Model.full_clean
>>>>>>
>>>>>> from django.core.exceptions import ValidationError, NON_FIELD_ERRORStry:
>>>>>>     article.full_clean()except ValidationError as e:
>>>>>>     non_field_errors = e.message_dict[NON_FIELD_ERRORS]
>>>>>>
>>>>>> It looks like it's not firing off that exception in your case --
>>>>>> unless it's being supressed somehow. Did you override anything else in 
>>>>>> that
>>>>>> Model? Or is this example literally 'it'?
>>>>>>
>>>>>>  On Fri, Jun 1, 2012 at 9:47 AM, David Markey <[email protected]>wrote:
>>>>>>
>>>>>>>  Hi All,
>>>>>>>
>>>>>>> Say I have this model
>>>>>>>
>>>>>>> class TestModel(models.Model):
>>>>>>>     my_test = models.CharField(max_length=512, blank=True)
>>>>>>>
>>>>>>> And I try this:
>>>>>>>
>>>>>>> In [1]: from core.base.models import TestModel
>>>>>>>
>>>>>>> In [2]: test_model = TestModel()
>>>>>>>
>>>>>>> In [3]: test_model.my_test =* ""*
>>>>>>>
>>>>>>> In [4]: test_model.full_clean()
>>>>>>>
>>>>>>> In [5]: test_model.save()
>>>>>>>
>>>>>>> *Ok cool, this is expected.*
>>>>>>> *
>>>>>>> *
>>>>>>> *How about:*
>>>>>>>
>>>>>>>
>>>>>>> In [6]: test_model2 = TestModel()
>>>>>>>
>>>>>>> In [7]: test_model2.my_test =* None*
>>>>>>>
>>>>>>> In [8]: test_model2.full_clean()
>>>>>>>
>>>>>>>  In [9]: test_model2.save()
>>>>>>>
>>>>>>> ##*IntegrityError raised*
>>>>>>>
>>>>>>> Is there a way for full_clean() to catch that the "my_test" field is
>>>>>>> Null when it shouldn't be, when blank=True?
>>>>>>>
>>>>>>> If I have blank=False, it wont validate when my_test="".
>>>>>>>
>>>>>>>
>>>>>>> Thanks
>>>>>>>
>>>>>>> David
>>>>>>>
>>>>>>> --
>>>>>>> You received this message because you are subscribed to the Google
>>>>>>> Groups "Django users" 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-users?hl=en.
>>>>>>>
>>>>>>
>>>>>>  --
>>>>>> You received this message because you are subscribed to the Google
>>>>>> Groups "Django users" 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-users?hl=en.
>>>>>>
>>>>>
>>>>>  --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "Django users" 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-users?hl=en.
>>>>>
>>>>
>>>>  --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Django users" 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-users?hl=en.
>>>>
>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" 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-users?hl=en.
>>>
>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" 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-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" 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-users?hl=en.

Reply via email to