Opened 4 years ago

Closed 4 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 poirier 4 years ago.

Download all attachments as: .zip

Change History (11)

comment:1 Changed 4 years ago by anonymous

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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 4 years ago by anonymous

  • Component changed from File uploads/storage to Documentation
  • Triage Stage changed from Unreviewed to Accepted

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 4 years ago by kmtracey

(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 4 years ago by lukeplant

  • Type set to Bug

comment:5 Changed 4 years ago by lukeplant

  • Severity set to Normal

comment:6 Changed 4 years ago by SmileyChris

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

comment:7 Changed 4 years ago by poirier

  • Owner changed from nobody to poirier
  • Status changed from new to assigned
  • UI/UX unset

Changed 4 years ago by poirier

comment:8 Changed 4 years ago by poirier

  • Easy pickings set
  • Has patch set

comment:9 Changed 4 years ago by poirier

  • Owner changed from poirier to nobody
  • Status changed from assigned to new

comment:10 Changed 4 years ago by kmtracey

  • Resolution set to fixed
  • Status changed from new to closed

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