Code

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#15963 closed Cleanup/optimization (fixed)

Misleading FileField.save documentation, no reference to django.core.files.File

Reported by: ejucovy Owned by: nobody
Component: Documentation Version: 1.3
Severity: Normal Keywords:
Cc: ethan.jucovy@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX:

Description

The documentation for FileField.save (http://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.FieldFile.save) claims:

Takes two required arguments: name which is the name of the file, and content which is a file-like object containing the file's contents.

This is incorrect; content is *not* a "file-like object" -- it's a django.core.files.File-like object.

Attempting to do field.save(name, open(my_file)) results in an AttributeError: 'file' object has no attribute 'chunks'. The correct spelling is instead field.save(name, django.core.files.File(open(my_file))).

I've attached a patch to the docs which makes this clear, and also refers the reader to the documentation about Django File objects.

Attachments (2)

file_objects.diff (1.4 KB) - added by ejucovy 3 years ago.
file_objects.2.diff (1.4 KB) - added by ejucovy 3 years ago.

Download all attachments as: .zip

Change History (9)

Changed 3 years ago by ejucovy

comment:1 Changed 3 years ago by ejucovy

  • Cc ethan.jucovy@… added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 3 years ago by aaugustin

  • Triage Stage changed from Unreviewed to Accepted

These other tickets are related to FileField's documentation, but they don't describe this specific problem: #9535 (very broad), #15588 (already RFC), and #15646.

comment:3 Changed 3 years ago by patchhammer

  • Patch needs improvement set

file_objects.diff fails to apply cleanly on to trunk

Changed 3 years ago by ejucovy

comment:4 Changed 3 years ago by ejucovy

  • Patch needs improvement unset

Original patch was generated from within the docs/ directory. New patch file_objects.2.diff should apply cleanly from the root of the checkout.

comment:5 Changed 3 years ago by dmclain

  • Triage Stage changed from Accepted to Ready for checkin

comment:6 Changed 3 years ago by SmileyChris

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

In [16207]:

Fixes #15963 -- Misleading FileField.save documentation. Thanks for the report and patch, ejucovy.

comment:7 Changed 3 years ago by SmileyChris

In [16208]:

[1.3.X] Fixes #15963 -- Misleading FileField.save documentation. Thanks for the report and patch, ejucovy.

Backport of r16207 from trunk.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.