[Django] #22374: Suggest to validate unique before running clean in models full_clean etc..

8 views
Skip to first unread message

Django

unread,
Apr 2, 2014, 10:18:03 AM4/2/14
to django-...@googlegroups.com
#22374: Suggest to validate unique before running clean in models full_clean etc..
----------------------------------------------+--------------------
Reporter: dspjmt@… | Owner: nobody
Type: Bug | Status: new
Component: Database layer (models, ORM) | Version: 1.6
Severity: Release blocker | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+--------------------
If we use clean(), and check for fields the hasn't been assigned, then it
will raise a doesnotexist exception.

The clean() method claims we can utilize fields which data is clean, it's
not, will in validation of uniqueness, the missing of fields will be
suggested successfully, I think we should check if the field exists first.

--
Ticket URL: <https://code.djangoproject.com/ticket/22374>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Apr 7, 2014, 7:45:40 AM4/7/14
to django-...@googlegroups.com
#22374: Suggest to validate unique before running clean in models full_clean etc..
-------------------------------------+-------------------------------------

Reporter: dspjmt@… | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.6
(models, ORM) | Resolution:
Severity: Normal | Triage Stage:
Keywords: | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timo):

* needs_better_patch: => 0
* severity: Release blocker => Normal
* needs_tests: => 0
* needs_docs: => 0


Comment:

Sorry, I'm having trouble understanding your report. Could you give an
example?

--
Ticket URL: <https://code.djangoproject.com/ticket/22374#comment:1>

Django

unread,
Apr 9, 2014, 7:47:56 AM4/9/14
to django-...@googlegroups.com
#22374: Suggest to validate unique before running clean in models full_clean etc..
-------------------------------------+-------------------------------------
Reporter: dspjmt@… | Owner: nobody
Type: Bug | Status: closed

Component: Database layer | Version: 1.6
(models, ORM) | Resolution: needsinfo

Severity: Normal | Triage Stage:
Keywords: | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timo):

* status: new => closed
* resolution: => needsinfo


--
Ticket URL: <https://code.djangoproject.com/ticket/22374#comment:2>

Django

unread,
Apr 21, 2014, 6:22:53 AM4/21/14
to django-...@googlegroups.com
#22374: Suggest to validate unique before running clean in models full_clean etc..
-------------------------------------+-------------------------------------
Reporter: dspjmt@… | Owner: nobody

Type: Bug | Status: closed
Component: Database layer | Version: 1.6
(models, ORM) | Resolution: needsinfo
Severity: Normal | Triage Stage:
Keywords: | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Jimmy):

Let's say, I have a module like:

class A(Model):
b = IntegerField(max_length=3)

clean(self):
if b < 3:
raise ValidationError('Too large')

When we use a form, if b is not filled, error will happen because b don't
have a value. So we have to check if b has value, which was done in
validate_unique(). So why not validate_unique first and then call clean?

--
Ticket URL: <https://code.djangoproject.com/ticket/22374#comment:3>

Django

unread,
Apr 21, 2014, 6:24:07 AM4/21/14
to django-...@googlegroups.com
#22374: Suggest to validate unique before running clean in models full_clean etc..
-------------------------------------+-------------------------------------
Reporter: dspjmt@… | Owner: nobody

Type: Bug | Status: closed
Component: Database layer | Version: 1.6
(models, ORM) | Resolution: needsinfo
Severity: Normal | Triage Stage:
Keywords: | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Jimmy):

Replying to [comment:3 Jimmy]:


> Let's say, I have a module like:
>
> class A(Model):
> b = IntegerField(max_length=3)

Sorry, b = IntegerField()

>
> clean(self):
> if b < 3:
> raise ValidationError('Too large')
>
> When we use a form, if b is not filled, error will happen because b
don't have a value. So we have to check if b has value, which was done in
validate_unique(). So why not validate_unique first and then call clean?

--
Ticket URL: <https://code.djangoproject.com/ticket/22374#comment:4>

Django

unread,
Apr 21, 2014, 9:05:41 AM4/21/14
to django-...@googlegroups.com
#22374: Suggest to validate unique before running clean in models full_clean etc..
-------------------------------------+-------------------------------------
Reporter: dspjmt@… | Owner: nobody

Type: Bug | Status: closed
Component: Database layer | Version: 1.6
(models, ORM) | Resolution: wontfix

Severity: Normal | Triage Stage:
Keywords: | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timo):

* resolution: needsinfo => wontfix


Comment:

I don't think it's a good idea. In particular, there is no guarantee that
`validate_unique()` will be called. Note this comment in
`django.forms.models`:
{{{
# self._validate_unique will be set to True by BaseModelForm.clean().
# It is False by default so overriding self.clean() and failing to call
# super will stop validate_unique from being called.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/22374#comment:5>

Reply all
Reply to author
Forward
0 new messages