#34166: UniqueConstraint with condition not validated if the condition field is 
not
editable
-------------------------------------+-------------------------------------
     Reporter:  Márton Salomváry     |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  4.1
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  model validation     |             Triage Stage:
  unique constraint condition        |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Márton Salomváry):

 The problem seems to be that the non-editable field is passed down as part
 of `excludes`, which is right, we do not want to validate the value of the
 non-editable field.

 However this is not about validating the value of the non-editable field,
 but conditionally validating the value of a *different* field, if the non-
 editable field's value matches the condition.

 The documentation on the semantics of `excludes` seems to confirm this:
 
https://docs.djangoproject.com/en/4.1/ref/models/instances/#django.db.models.Model.full_clean
 "ModelForm uses this argument to exclude fields that aren’t present on
 your form from being validated since any errors raised could not be
 corrected by the user."

 I'm a little confused however because I found a test that seems to
 specifically verify this (but there is no explanation for the "why" or
 "for what purpose").
 
https://github.com/django/django/blob/e14d08cd894e9d91cb5d9f44ba7532c1a223f458/tests/constraints/tests.py#L698-L703

 I've also done a bit of Git archeology and found this conversation around
 the same problem which ends with "That's a suitable workaround, but I feel
 like it should not be necessary."
 https://github.com/django/django/pull/14625#pullrequestreview-1074071130

 Would a patch be accepted that makes the workaround unnecessary?

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

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/010701848189b839-738366bd-19a8-4559-bba1-8a811c8e37f7-000000%40eu-central-1.amazonses.com.

Reply via email to