#31774: validate_unique in Model class doesn't validate uniqueness for 
ImageField.
-------------------------------------+-------------------------------------
     Reporter:  Gaurav Ghildyal      |                    Owner:  nobody
         Type:  New feature          |                   Status:  closed
    Component:  Database layer       |                  Version:  3.0
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  needsinfo
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Gaurav Ghildyal):

 Oops, that's my mistake, wrong tar command! Will upload the correct one!

 Replying to [comment:3 Carlton Gibson]:
 > Hi Gaurav,
 >
 > Thanks for the follow-up. (I wasn't sure about the attachment: it's
 seemed like the whole project was saved as binary in the `manage.py` file
 — how did you create that? How would one run it? — Not something I've seen
 before, but I was able to look at it.)
 >
 > I'm going to move this to `needsinfo` — assuming a storage that didn't
 create unique names, I can see how this might come up.
 >
 > The storage issue is a bit of a distraction. The correct validation
 should be at the form layer:
 >
 > * Calling `form.is_valid()`, on a `ModelForm` using the image (or file
 field).
 > * In
 
[https://github.com/django/django/blob/156a2138db20abc89933121e4ff2ee2ce56a173a/django/forms/models.py#L383
 `_post_clean()`] we WOULD validate the uniqueness of the field.
 > * In a test case
 
[https://github.com/django/django/blob/156a2138db20abc89933121e4ff2ee2ce56a173a/django/forms/models.py#L310
 `_get_validation_exclusions()`] **included** the `logo` field — that's
 because of the `blank=True` on the model definition. That means
 `_post_clean()` will be skipped for it.
 >
 > Removing the `blank=True` allows `logo` not be excluded but I didn't
 have enough time to verify whether the image/file field would then trigger
 the expected error in `validate_unique()`. I may be able to get back to it
 (it's interesting) but if you could dig down deeper that would help.
 >
 > * I'd subclass `Storage` and override `.get_alternative_name()` to not
 do that properly.
 > * Then create a `ModelForm` with just the `logo` field to verify that
 `_post_clean()` triggers the uniqueness error.
 >
 > If not then we can see why not, and whether it can be adjusted.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/31774#comment:4>
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 django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.3052af674b5db3629c1af19afa2246f6%40djangoproject.com.

Reply via email to