You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Uniqueness validators should not be run for excluded (read_only) fields #2848
get_uniqueness_extra_kwargs and get_unique_together_validators both rely on Django's model unique_together specification. However, if read_only is set for both they should not be expected to be validated as normal. This reflects the behavior of django forms (exclude the field in form and it doesn't validated against this). This allows unique_together fields to be autogenerated in the save method of the model.
Activity
lovelydinosaur commentedon Apr 21, 2015
Presumably if either is read_only, then we shouldn't validate them? (Ie. same as excluding one?)
ntucker commentedon Apr 21, 2015
This is how django does it: https://github.com/django/django/blob/master/django/forms/models.py#L344 (build exclusion list)
Then here: https://github.com/django/django/blob/a10b4c010ab2cdaa6ba8bfaec3e3540299ea77be/django/db/models/base.py#L926
for name in check:
# If this is an excluded field, don't add this check.
if name in exclude:
break
So It looks like you are correct, a uniquetogether check is not done if ANY of the fields are missing
ntucker commentedon Apr 24, 2015
I can write a PR for this as long as the design is accepted. I just hate writing stuff that won't get approved.
lovelydinosaur commentedon Jun 25, 2015
I'm broadly in favor of this, but I don't think we can make any definite decisions without seeing an example fix and test case.
Labeling this as a valid bug to address tho.
21 remaining items