Code

#20427 closed Bug (fixed)

UnboundLocalError when file lock fails in storage.py

Reported by: mattias@… Owned by: nobody
Component: File uploads/storage Version: 1.5
Severity: Normal Keywords: storage.py, UnboundLocalError
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

After attempting to upload an image in the admin interface a received the following error:

UnboundLocalError at /admin/api/video/9/
local variable '_file' referenced before assignment

Origin of the error:
site-packages/django/core/files/storage.py in _save
209: if _file is not None:

Most likely the lock attempt in the try block fails because the write is on an NFS share and there is some issue with permissions or something.
I personally think that the script still shouldn't crash like this.

Attachments (0)

Change History (3)

comment:1 Changed 14 months ago by bmispelon

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from Uncategorized to Bug

Hi,

Thanks for your report, this looks indeed like a bug in the logic flow.

Your analysis is correct: this error will happen if the locking raises an exception.

comment:2 Changed 14 months ago by bmispelon

For reference, it seems like this issue was introduced in commit 4e70ad11d29bde54b846920ce0dcf8d10741d3ae.

comment:3 Changed 14 months ago by Claude Paroz <claude@…>

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

In 838f28974e0711f4184798ba5e54ad725bc112f0:

Fixed #20427 -- Moved a variable initialization in storage.py

This is fixing commit 4e70ad11d2. Thanks mattias at elements.nl
for the report and Baptiste Mispelon for identifying the faulty
commit.

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.