#34237: FileField does not take upload_to into account when setting unique=True
-------------------------------------+-------------------------------------
Reporter: 0x4A-0x41-0x4B | Owner: nobody
Type: Bug | Status: closed
Component: File | Version: 4.1
uploads/storage |
Severity: Normal | Resolution: invalid
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 Mariusz Felisiak):
* status: new => closed
* resolution: => invalid
Comment:
Replying to [ticket:34237 0x4A-0x41-0x4B]:
> #27188 added support for setting unique=True to the FileField.
> This does not seem to take the upload_to argument into account.
As far as I'm aware, `upload_to` directory is concatenated with the `name`
and accounted for by an unique constraint.
> As upload_to could be used to completely change the name of the uploaded
file it should, in my opinion, be considered part of the filename.
> Or should at the very least be mentioned in the docs for clarity.
>
> If upload_to is defined, setting unique=True does effectively nothing
right now.
That's not true. `unique=True` only means that a database-level constraint
is created.
> The file is passed on and a unique filename is generated (->The default
behavior of adding an underscore followed by seven random characters)
instead of raising an error.
It depends on the implementation of `storage.generate_filename()`. The
database constraint is the last frontier where uniqueness is protected.
--
Ticket URL: <https://code.djangoproject.com/ticket/34237#comment:2>
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/0107018570d99ec1-1b8ddc0b-0a77-4124-9278-fb50bfabb9eb-000000%40eu-central-1.amazonses.com.