Opened 10 years ago

Closed 9 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: master
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: UI/UX:

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 10 years ago by anonymous

Cc: sam@… added

comment:2 Changed 10 years ago by Chris Beaven

Summary: IntegrityError django.newformsnewforms form_for_* methods don't automatically validate against unique_together
Triage Stage: UnreviewedDesign decision needed

You're right, they don't automatically validate against unique_together currently.

Whether they should or not is up for debate.

comment:3 Changed 10 years ago by Malcolm Tredinnick

Triage Stage: Design decision neededAccepted

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 10 years ago by Brian Rosner

Marked #5736 as a duplicate. unique and unique_together will be fixed with some model aware validation that Malcolm mentions above.

comment:5 Changed 10 years ago by nix

Cc: listuser@… added

comment:6 Changed 10 years ago by David Larlet

Cc: larlet@… added

comment:7 Changed 10 years ago by nix

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 10 years ago by Gábor Farkas <gabor@…>

Cc: gabor@… added

comment:9 Changed 10 years ago by Mike Scott

Cc: micsco@… added

comment:10 Changed 9 years ago by ipse <ipse.reg@…>

Cc: ipse.reg@… added

Any progress on this?
I'm still getting this exception when UNIQUE is violated.

comment:11 Changed 9 years ago by David Larlet

form_for_* are now deprecated and replaced by ModelForm so the bug should be tested with it I guess.

comment:12 Changed 9 years ago by ipse <ipse.reg@…>

It is still here with ModelForms (I'm using them, not form_for_*).

comment:13 Changed 9 years ago by Favo Yang <favo@…>

also missing field's unique=True support.

comment:14 Changed 9 years ago by mrts

See http://www.djangosnippets.org/snippets/649/ for a workaround that can be used until model validation gets integrated.

comment:15 Changed 9 years ago by anonymous

comment:16 in reply to:  14 Changed 9 years ago by anonymous

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

comment:17 Changed 9 years ago by mrts

Resolution: duplicate
Status: newclosed

Duplicate of #6845.

Note: See TracTickets for help on using tickets.
Back to Top