Opened 6 years ago

Closed 5 years ago

#15646 closed Bug (fixed)

Document that the FileField's path can not be relied on until the model is saved

Reported by: anonymous Owned by: nobody
Component: Documentation Version: 1.2
Severity: Normal Keywords: storage system path upload_to
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

The FileField's .path attribute misses the path given in 'upload_to'.

Example:
In settings.py:

MEDIA_ROOT = '/somewhere/'

In some model:

data = models.FileField(upload_to='files')

In the view that handles the file upload:

print data.path

This prints '/somewhere/filename' but if I am correct it shall print '/somewhere/files/filename'
Exact Version is 1.2.5(-1) (current version in debian/wheezy)
upload_to='files/' does not remedy this issue.
I sincerely hope that I am not wasting your time.
Thank you.

Attachments (1)

15646.diff (1.3 KB) - added by Dan Poirier 5 years ago.

Download all attachments as: .zip

Change History (11)

comment:1 Changed 6 years ago by anonymous

ADDENDUM:

Saving the instance apparently constructs the right path and fills it in. Due to the fact, that uploaded files often need processing -- for instance converting them to a different file format -- I would find it most reasonable to change that behaviour. Please consider.

Thank you.

comment:2 Changed 6 years ago by anonymous

Component: File uploads/storageDocumentation
Triage Stage: UnreviewedAccepted

This is #10788. It was determined back then that it is not fixable in a reasonable fashion, so the change from previous was documented in the release notes:

http://docs.djangoproject.com/en/1.1/releases/1.1/#names-of-uploaded-files-are-available-later

However I don't see that we documented this anywhere in the main docs, and we should. (Or maybe we do, and I just can't find it...I can't seem to find anywhere that we actually document the path attribute of a model FileField?) Accepting as a ticket against the docs.

comment:3 Changed 6 years ago by Karen Tracey

(Sorry, that was me. Somehow I can now post as anonymous where in the past I'd always get the rejected as potential spam message on anything as soon as trac logged me out.)

comment:4 Changed 6 years ago by Luke Plant

Type: Bug

comment:5 Changed 6 years ago by Luke Plant

Severity: Normal

comment:6 Changed 6 years ago by Chris Beaven

Easy pickings: unset
Summary: FileField's path attribute lacks 'upload_to' bit.Document that the FileField's path can not be relied on until the model is saved

comment:7 Changed 5 years ago by Dan Poirier

Owner: changed from nobody to Dan Poirier
Status: newassigned
UI/UX: unset

Changed 5 years ago by Dan Poirier

Attachment: 15646.diff added

comment:8 Changed 5 years ago by Dan Poirier

Easy pickings: set
Has patch: set

comment:9 Changed 5 years ago by Dan Poirier

Owner: changed from Dan Poirier to nobody
Status: assignednew

comment:10 Changed 5 years ago by Karen Tracey

Resolution: fixed
Status: newclosed

In [17113]:

Fix #15646: Document that a FileField's full path can't be relied upon until its model has been saved to the database. Thanks poirier.

Note: See TracTickets for help on using tickets.
Back to Top