Opened 6 years ago

Closed 4 years ago

#14681 closed Bug (fixed)

Uploaded files should not set mode to None

Reported by: bgreenlee Owned by: bretth
Component: File uploads/storage Version: master
Severity: Normal Keywords: sprintdec2010
Cc: moritz.sichert@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


I ran across this issue when attempting to open an uploaded file with GzipFile(fileobj=uploaded_file). If you don't pass in the mode parameter as well, GzipFile crashes. GzipFile looks to see if the fileobj has a mode attribute, and if it does, it uses it; however, using a mode of None causes it to crash.

I filed a bug and patch for GzipFile (, but it was rejected, saying that the bug was in Django for setting the mode on the file to None. So I've attached a patch (with test) to django.core.files.base.File that only sets mode if mode is present.

Attachments (3)

django_mode_patch.diff (1.1 KB) - added by bgreenlee 6 years ago.
revisedtest.diff (882 bytes) - added by bretth 6 years ago.
14681_unified.diff (1.6 KB) - added by dmclain 5 years ago.
unified the two patches and fixed a bug in one of the tests

Download all attachments as: .zip

Change History (10)

Changed 6 years ago by bgreenlee

Changed 6 years ago by bretth

comment:1 Changed 6 years ago by bretth

  • Keywords sprintdec2010 added
  • milestone set to 1.3
  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to bretth
  • Patch needs improvement unset
  • Status changed from new to assigned
  • Triage Stage changed from Unreviewed to Accepted

Added a revised test patch to explicity test against stdlib gzip.Gzip which is the point of failure.

To expand, python expects the mode attr to be from the usual 'r','w' etc list or not set at all on a file like object.

comment:2 Changed 5 years ago by jaddison

  • milestone 1.3 deleted
  • Severity set to Normal
  • Type set to Bug

comment:3 Changed 5 years ago by patchhammer

  • Easy pickings unset
  • Patch needs improvement set

revisedtest.diff fails to apply cleanly on to trunk

Changed 5 years ago by dmclain

unified the two patches and fixed a bug in one of the tests

comment:4 Changed 5 years ago by dmclain

  • Patch needs improvement unset

comment:5 Changed 5 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:6 Changed 4 years ago by moritzs

  • Cc moritz.sichert@… added
  • Triage Stage changed from Accepted to Ready for checkin

comment:7 Changed 4 years ago by Claude Paroz <claude@…>

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

In [2626ea4a74d09642a50c3fb30944513b68dda289]:

Fixed #14681 -- Do not set mode to None on file-like objects.

gzip.GzipFile does not support files with mode set to None.

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