#22374 closed Bug (wontfix)
Suggest to validate unique before running clean in models full_clean etc..
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.6 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
If we use clean(), and check for fields the hasn't been assigned, then it will raise a doesnotexist exception.
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.
Change History (5)
comment:1 by , 11 years ago
Severity: | Release blocker → Normal |
---|
comment:2 by , 11 years ago
Resolution: | → needsinfo |
---|---|
Status: | new → closed |
follow-up: 4 comment:3 by , 11 years ago
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?
comment:4 by , 11 years ago
Replying to 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?
comment:5 by , 11 years ago
Resolution: | needsinfo → wontfix |
---|
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.
Sorry, I'm having trouble understanding your report. Could you give an example?