Opened 18 years ago
Closed 17 years ago
#4895 closed (duplicate)
newforms form_for_* methods don't automatically validate against unique_together
| Reported by: | Jungle | Owned by: | nobody |
|---|---|---|---|
| Component: | Forms | Version: | dev |
| Severity: | Keywords: | IntegrityError django.newforms | |
| Cc: | sam@…, listuser@…, larlet@…, gabor@…, micsco@…, ipse.reg@… | Triage Stage: | Accepted |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
method is_valid don't return error for unique fields
I'm using this model
class Account(models.Model):
provider = models.ForeignKey(Provider, verbose_name = 'Provider')
percent = models.PositiveSmallIntegerField(u'Percent', null = True, blank = True)
aid = models.PositiveIntegerField(u'Affiliate ID')
skey = models.CharField(u'Secret key', maxlength = 256, blank = True)
class Meta:
unique_together = (('provider', 'aid'),)
When I try create instance of Account with exists fields in DB it raise IntegrityError
P.S. sorry for my English
Change History (17)
comment:1 by , 18 years ago
| Cc: | added |
|---|
comment:2 by , 18 years ago
| Summary: | IntegrityError django.newforms → newforms form_for_* methods don't automatically validate against unique_together |
|---|---|
| Triage Stage: | Unreviewed → Design decision needed |
comment:3 by , 18 years ago
| Triage Stage: | Design decision needed → Accepted |
|---|
This gets fixed once Jacob has finished the model-aware validation stuff we started working on at OSCON. Things like this must be validated in the model, not the form, but for the form_for_* cases, the model's errors should then be fed back to the form. So the problem is real, but we are fixing it in a more holistic fashion than just tweaking form_for_*.
comment:4 by , 18 years ago
Marked #5736 as a duplicate. unique and unique_together will be fixed with some model aware validation that Malcolm mentions above.
comment:5 by , 18 years ago
| Cc: | added |
|---|
comment:6 by , 18 years ago
| Cc: | added |
|---|
comment:7 by , 18 years ago
What is the ETA on the "model aware validation" changes? (I am trying to decide how much effort to spend working around this bug)
comment:8 by , 18 years ago
| Cc: | added |
|---|
comment:9 by , 18 years ago
| Cc: | added |
|---|
comment:10 by , 18 years ago
| Cc: | added |
|---|
Any progress on this?
I'm still getting this exception when UNIQUE is violated.
comment:11 by , 18 years ago
form_for_* are now deprecated and replaced by ModelForm so the bug should be tested with it I guess.
follow-up: 16 comment:14 by , 18 years ago
See http://www.djangosnippets.org/snippets/649/ for a workaround that can be used until model validation gets integrated.
comment:15 by , 17 years ago
comment:16 by , 17 years ago
Replying to mrts:
See http://www.djangosnippets.org/snippets/649/ for a workaround that can be used until model validation gets integrated.
doesn't handle i18n
You're right, they don't automatically validate against
unique_togethercurrently.Whether they should or not is up for debate.