#32718: [3.2.1] Issue with assigning file to FileField
-------------------------------------+-------------------------------------
     Reporter:  Jakub Kleň           |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  3.2
  (models, ORM)                      |
     Severity:  Release blocker      |               Resolution:
     Keywords:  3.2.1 file model     |             Triage Stage:  Accepted
  filefield fieldfile                |
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Florian Apolloner):

 Replying to [comment:7 Mariusz Felisiak]:
 > > Correct me if I'm wrong, but this fix and also this ​commit breaks the
 Django file storage completely...
 >
 > It's
 
[https://docs.djangoproject.com/en/3.2/ref/models/fields/#django.db.models.fields.files.FieldFile.save
 documented] that the `FieldField.save()'s` `name` argument ''"is the name
 of the file"'' not a path. You can define `upload_to` as a function to use
 subdirectories, see an example in `FileField.upload_to`
 
[https://docs.djangoproject.com/en/3.2/ref/models/fields/#django.db.models.FileField.upload_to
 docs].

 Outch, sadly it is not that simple. When you look at your documentation
 link about the `.save()` method it says:
 > Note that the content argument should be an instance of
 django.core.files.File, not Python’s built-in file object. You can
 construct a File from an existing Python file object like this:

 This one links to
 https://docs.djangoproject.com/en/3.2/ref/files/file/#django.core.files.File
 which says `name` is
 > The name of the file including the relative path from MEDIA_ROOT.

 And now all fixes are getting ugly… So now the question becomes: If you do
 `File(…, name='path/to/something.txt')` and then call `.save(…)`, what
 should be the final path? Should it add the full relative path to
 `upload_to`, should it take the basename and set that in conjunction to
 `upload_to` or should it just take the path as is?

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32718#comment:8>
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/064.000d96c3942a62e61975363d59bb8769%40djangoproject.com.

Reply via email to