Django

Code

Ticket #4895 (closed: duplicate)

Opened 2 years ago

Last modified 1 year ago

newforms form_for_* methods don't automatically validate against unique_together

Reported by: Jungle Assigned to: nobody
Milestone: Component: Forms
Version: SVN Keywords: IntegrityError django.newforms
Cc: sam@robots.org.uk, listuser@peternixon.net, larlet@gmail.com, gabor@nekomancer.net, micsco@gmail.com, ipse.reg@gmail.com Triage Stage: Accepted
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

Attachments

Change History

07/20/07 08:21:59 changed by anonymous

  • cc set to sam@robots.org.uk.
  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

08/14/07 23:38:11 changed by SmileyChris

  • summary changed from IntegrityError django.newforms to newforms form_for_* methods don't automatically validate against unique_together.
  • stage changed from Unreviewed to Design decision needed.

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

Whether they should or not is up for debate.

08/15/07 04:59:14 changed by mtredinnick

  • stage changed from Design decision needed to 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_*.

10/11/07 09:16:41 changed by brosner

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

10/14/07 07:42:34 changed by nix

  • cc changed from sam@robots.org.uk to sam@robots.org.uk, listuser@peternixon.net.

10/15/07 08:18:13 changed by david

  • cc changed from sam@robots.org.uk, listuser@peternixon.net to sam@robots.org.uk, listuser@peternixon.net, larlet@gmail.com.

10/15/07 09:55:51 changed 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)

10/15/07 10:20:51 changed by Gábor Farkas <gabor@nekomancer.net>

  • cc changed from sam@robots.org.uk, listuser@peternixon.net, larlet@gmail.com to sam@robots.org.uk, listuser@peternixon.net, larlet@gmail.com, gabor@nekomancer.net.

10/16/07 01:32:58 changed by micsco

  • cc changed from sam@robots.org.uk, listuser@peternixon.net, larlet@gmail.com, gabor@nekomancer.net to sam@robots.org.uk, listuser@peternixon.net, larlet@gmail.com, gabor@nekomancer.net, micsco@gmail.com.

01/05/08 12:59:53 changed by ipse <ipse.reg@gmail.com>

  • cc changed from sam@robots.org.uk, listuser@peternixon.net, larlet@gmail.com, gabor@nekomancer.net, micsco@gmail.com to sam@robots.org.uk, listuser@peternixon.net, larlet@gmail.com, gabor@nekomancer.net, micsco@gmail.com, ipse.reg@gmail.com.

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

01/05/08 13:07:14 changed by david

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

01/05/08 13:22:26 changed by ipse <ipse.reg@gmail.com>

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

01/26/08 02:46:29 changed by Favo Yang <favo@exoweb.net>

also missing field's unique=True support.

(follow-up: ↓ 16 ) 03/23/08 08:55:54 changed by mrts

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

05/07/08 01:53:19 changed by anonymous

  • cc changed from sam@robots.org.uk, listuser@peternixon.net, larlet@gmail.com, gabor@nekomancer.net, micsco@gmail.com, ipse.reg@gmail.com to sam@robots.org.uk, listuser@peternixon.net, larlet@gmail.com, gabor@nekomancer.net, micsco@gmail.com, ipse.reg@gmail.com.

(in reply to: ↑ 14 ) 06/02/08 06:52:54 changed 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

06/12/08 15:33:15 changed by mrts

  • status changed from new to closed.
  • resolution set to duplicate.

Duplicate of #6845.


Add/Change #4895 (newforms form_for_* methods don't automatically validate against unique_together)




Change Properties
Action