[Django] #22307: tempfile.SpooledTemporaryFile passed to File causes exception

2 views
Skip to first unread message

Django

unread,
Mar 21, 2014, 1:19:29 PM3/21/14
to django-...@googlegroups.com
#22307: tempfile.SpooledTemporaryFile passed to File causes exception
------------------------------+--------------------
Reporter: hrlawrenz@… | Owner: nobody
Type: Bug | Status: new
Component: Core (Other) | Version: 1.6
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------
When a File object is created from a tempfile.SpooledTemporaryFile, an
exception occurs when the File.size method is called and the
tempfile.SpooledTemporaryFile isn't large enough to have been written to
disk. The exception is caused by an attempt to call os.path.exists on a
None value. The name attribute of the tempfile.SpooledTemporaryFile in
this case is None in this case because it doesn't exist on disk.

Patch in pull request at https://github.com/django/django/pull/2455

The patch just adds another condition before calling os.path.exists to
verify that the file name isn't None.


Traceback (most recent call last):
File "/Users/hrwl/Documents/Projects/django/tests/files/tests.py", line
215, in test_in_memory_spooled_temp
self.assertTrue(django_file.size, 17)
File "/Users/hrwl/Documents/Projects/django/django/core/files/base.py",
line 43, in _get_size
elif hasattr(self.file, 'name') and os.path.exists(self.file.name):
File
"/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/genericpath.py",
line 18, in exists
os.stat(path)
TypeError: coercing to Unicode: need string or buffer, NoneType found

--
Ticket URL: <https://code.djangoproject.com/ticket/22307>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 21, 2014, 3:29:45 PM3/21/14
to django-...@googlegroups.com
#22307: tempfile.SpooledTemporaryFile passed to File causes exception
------------------------------+------------------------------------

Reporter: hrlawrenz@… | Owner: nobody
Type: Bug | Status: new
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------
Changes (by bmispelon):

* needs_better_patch: => 1
* version: 1.6 => master
* stage: Unreviewed => Accepted
* needs_tests: => 0
* needs_docs: => 0


Comment:

Hi,

There's some trailing whitespace and the added test doesn't work on
Python3.

Looks good otherwise.

--
Ticket URL: <https://code.djangoproject.com/ticket/22307#comment:1>

Django

unread,
Mar 21, 2014, 5:35:30 PM3/21/14
to django-...@googlegroups.com
#22307: tempfile.SpooledTemporaryFile passed to File causes exception
------------------------------+------------------------------------
Reporter: hrlawrenz@… | Owner: nobody
Type: Bug | Status: closed

Component: Core (Other) | Version: master
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------
Changes (by Baptiste Mispelon <bmispelon@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"918a16bc4c099ab0cae72a231de3e99e2a9d02cb"]:
{{{
#!CommitTicketReference repository=""
revision="918a16bc4c099ab0cae72a231de3e99e2a9d02cb"
Fixed #22307 -- Fixed SpooledTemporaryFile bug in File class.

Added condition to prevent checking the existence of a file name of a
file like object when the name attribute is None. This is necessary
because a SpooledTemporaryFile won't exist on the file system or have a
name until it has reached its max_size. Also added tests.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/22307#comment:2>

Django

unread,
Mar 22, 2014, 3:55:42 AM3/22/14
to django-...@googlegroups.com
#22307: tempfile.SpooledTemporaryFile passed to File causes exception
------------------------------+------------------------------------

Reporter: hrlawrenz@… | Owner: nobody
Type: Bug | Status: new
Component: Core (Other) | Version: master
Severity: Normal | Resolution:

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------
Changes (by aaugustin):

* status: closed => new
* resolution: fixed =>


Comment:

This commit causes a test failure under Python 3:

http://ci.djangoproject.com/job/Django/database=sqlite3,python=python3.2/4220/testReport/junit/files.tests/SpooledTempTests/test_written_spooled_temp/

--
Ticket URL: <https://code.djangoproject.com/ticket/22307#comment:3>

Django

unread,
Mar 22, 2014, 6:18:24 AM3/22/14
to django-...@googlegroups.com
#22307: tempfile.SpooledTemporaryFile passed to File causes exception
-------------------------------------+-------------------------------------

Reporter: hrlawrenz@… | Owner: nobody
Type: Bug | Status: new
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
Has patch: 1 | checkin
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by aaugustin):

* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin


Comment:

Baptiste, can you review and merge
https://github.com/django/django/pull/2459?

--
Ticket URL: <https://code.djangoproject.com/ticket/22307#comment:4>

Django

unread,
Mar 22, 2014, 1:07:22 PM3/22/14
to django-...@googlegroups.com
#22307: tempfile.SpooledTemporaryFile passed to File causes exception
-------------------------------------+-------------------------------------

Reporter: hrlawrenz@… | Owner: nobody
Type: Bug | Status: new
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
Has patch: 1 | checkin
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Baptiste Mispelon <bmispelon@…>):

In [changeset:"96fc3908ad25f40b4c6e2f76be2639f665223227"]:
{{{
#!CommitTicketReference repository=""
revision="96fc3908ad25f40b4c6e2f76be2639f665223227"
Fixed a failing test introduced in
918a16bc4c099ab0cae72a231de3e99e2a9d02cb.

Refs #22307.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/22307#comment:5>

Django

unread,
Mar 22, 2014, 1:46:59 PM3/22/14
to django-...@googlegroups.com
#22307: tempfile.SpooledTemporaryFile passed to File causes exception
-------------------------------------+-------------------------------------
Reporter: hrlawrenz@… | Owner: nobody
Type: Bug | Status: closed

Component: Core (Other) | Version: master
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
Has patch: 1 | checkin
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by bmispelon):

* status: new => closed
* resolution: => fixed


Comment:

That fixed it.

Thanks for the heads up.

--
Ticket URL: <https://code.djangoproject.com/ticket/22307#comment:6>

Reply all
Reply to author
Forward
0 new messages