Opened 17 years ago

Closed 16 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 anonymous, 17 years ago

Cc: sam@… added

comment:2 by Chris Beaven, 17 years ago

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 by Malcolm Tredinnick, 17 years ago

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 by Brian Rosner, 16 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 nix, 16 years ago

Cc: listuser@… added

comment:6 by David Larlet, 16 years ago

Cc: larlet@… added

comment:7 by nix, 16 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 Gábor Farkas <gabor@…>, 16 years ago

Cc: gabor@… added

comment:9 by Mike Scott, 16 years ago

Cc: micsco@… added

comment:10 by ipse <ipse.reg@…>, 16 years ago

Cc: ipse.reg@… added

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

comment:11 by David Larlet, 16 years ago

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

comment:12 by ipse <ipse.reg@…>, 16 years ago

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

comment:13 by Favo Yang <favo@…>, 16 years ago

also missing field's unique=True support.

comment:14 by mrts, 16 years ago

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

comment:15 by anonymous, 16 years ago

in reply to:  14 comment:16 by anonymous, 16 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

comment:17 by mrts, 16 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #6845.

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