The clean() method claims we can utilize fields which data is clean, it's
not, will in validation of uniqueness, the missing of fields will be
suggested successfully, I think we should check if the field exists first.
--
Ticket URL: <https://code.djangoproject.com/ticket/22374>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* severity: Release blocker => Normal
* needs_tests: => 0
* needs_docs: => 0
Comment:
Sorry, I'm having trouble understanding your report. Could you give an
example?
--
Ticket URL: <https://code.djangoproject.com/ticket/22374#comment:1>
* status: new => closed
* resolution: => needsinfo
--
Ticket URL: <https://code.djangoproject.com/ticket/22374#comment:2>
Comment (by Jimmy):
Let's say, I have a module like:
class A(Model):
b = IntegerField(max_length=3)
clean(self):
if b < 3:
raise ValidationError('Too large')
When we use a form, if b is not filled, error will happen because b don't
have a value. So we have to check if b has value, which was done in
validate_unique(). So why not validate_unique first and then call clean?
--
Ticket URL: <https://code.djangoproject.com/ticket/22374#comment:3>
Comment (by Jimmy):
Replying to [comment:3 Jimmy]:
> Let's say, I have a module like:
>
> class A(Model):
> b = IntegerField(max_length=3)
Sorry, b = IntegerField()
>
> clean(self):
> if b < 3:
> raise ValidationError('Too large')
>
> When we use a form, if b is not filled, error will happen because b
don't have a value. So we have to check if b has value, which was done in
validate_unique(). So why not validate_unique first and then call clean?
--
Ticket URL: <https://code.djangoproject.com/ticket/22374#comment:4>
* resolution: needsinfo => wontfix
Comment:
I don't think it's a good idea. In particular, there is no guarantee that
`validate_unique()` will be called. Note this comment in
`django.forms.models`:
{{{
# self._validate_unique will be set to True by BaseModelForm.clean().
# It is False by default so overriding self.clean() and failing to call
# super will stop validate_unique from being called.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/22374#comment:5>