Opened 16 years ago
Closed 15 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 Changed 16 years ago by
Cc: | sam@… added |
---|
comment:2 Changed 16 years ago by
Summary: | IntegrityError django.newforms → newforms form_for_* methods don't automatically validate against unique_together |
---|---|
Triage Stage: | Unreviewed → Design decision needed |
comment:3 Changed 16 years ago by
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 Changed 16 years ago by
Marked #5736 as a duplicate. unique and unique_together will be fixed with some model aware validation that Malcolm mentions above.
comment:5 Changed 16 years ago by
Cc: | listuser@… added |
---|
comment:6 Changed 16 years ago by
Cc: | larlet@… added |
---|
comment:7 Changed 16 years ago by
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 Changed 16 years ago by
Cc: | gabor@… added |
---|
comment:9 Changed 16 years ago by
Cc: | micsco@… added |
---|
comment:10 Changed 16 years ago by
Cc: | ipse.reg@… added |
---|
Any progress on this?
I'm still getting this exception when UNIQUE is violated.
comment:11 Changed 16 years ago by
form_for_* are now deprecated and replaced by ModelForm so the bug should be tested with it I guess.
comment:12 Changed 16 years ago by
It is still here with ModelForms (I'm using them, not form_for_*).
comment:14 follow-up: 16 Changed 16 years ago by
See http://www.djangosnippets.org/snippets/649/ for a workaround that can be used until model validation gets integrated.
comment:15 Changed 16 years ago by
comment:16 Changed 16 years ago by
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_together
currently.Whether they should or not is up for debate.