#34237: FileField does not take upload_to into account when setting unique=True
-------------------------------------+-------------------------------------
     Reporter:  0x4A-0x41-0x4B       |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  File                 |                  Version:  4.1
  uploads/storage                    |
     Severity:  Normal               |               Resolution:
     Keywords:  FileField, Unique,   |             Triage Stage:
  Storage, Upload                    |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by 0x4A-0x41-0x4B):

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


Comment:

 Replying to [comment:2 Mariusz Felisiak]:
 > As far as I'm aware, `upload_to` directory is concatenated with the
 `name` and accounted for by an unique constraint.
 This is strictly taken from the documentation (i have not yet looked into
 the source to back this up). If you define a custom upload_to callback, it
 will be passed on directly to the storage's save method (as mentioned in
 the
 
[https://docs.djangoproject.com/en/4.1/ref/models/fields/#django.db.models.FileField.upload_to
 documentation]).

 > That's not true. `unique=True` only means that a database-level
 constraint is created.
 Yep, that's true, sorry for the mistake on my part.

 > It depends on the implementation of `storage.generate_filename()`. The
 database constraint is the last frontier where uniqueness is protected.
 Well, what's the point of upload_to then? Why would i ever use the
 FileField's upload_to, if i can use the storage's generate_filename
 method?

 This puts up a barrier for anyone trying to enforce a purely unique set of
 file entries. The documentation for this is, if nothing else, misleading:
 > This attribute provides a way of setting the upload directory and file
 name ...
 
[https://docs.djangoproject.com/en/4.1/ref/models/fields/#django.db.models.FileField.upload_to
 Source]
 As its clearly NOT used to set the filename if the storage can (and will)
 completely disregard it.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34237#comment:3>
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/010701858e1342f5-0966dda0-c6d8-468f-a995-ab00c9b1b145-000000%40eu-central-1.amazonses.com.

Reply via email to