Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#16569 closed Bug (invalid)

NamedTemporaryFile is missing the delete argument

Reported by: Leon van der Ree Owned by: nobody
Component: Core (Other) Version: 1.3
Severity: Normal Keywords: NamedTemporaryFile, delete
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I am developing under Linux, while my test server is running Windows, which made me aware of the following error.

I wrote the following piece of code:
[code]
from django.core.files.temp import NamedTemporaryFile

img_temp = NamedTemporaryFile(delete=True)
code
which works fine under Linux, but fails under Windows.

I looked at the code in the django.core.files.temp module, and see it makes a distinction between Windows and other systems:

[code]
if os.name == 'nt':
code
in which case NamedTemporaryFile = TemporaryFile as defined above it.

However, according to http://docs.python.org/library/tempfile.html#tempfile.NamedTemporaryFile NamedTemporaryFile should be able to handle delete as well!

A solution would be to define NamedTemporaryFile as follows:
[code]

class NamedTemporaryFile(TemporaryFile):

def init(self, kwargs):

kwargs.pop('delete', True) # TODO: handle this delete flag
super(NamedTemporaryFile,self).init(kwargs)

code
But I haven't thought about how to handle the delete argument.

Change History (3)

comment:1 by Aymeric Augustin, 13 years ago

Has patch: unset
Resolution: invalid
Status: newclosed

NamedTemporaryFile isn't a public API — there isn't any reference to this class in the documentation: https://docs.djangoproject.com/search/?q=NamedTemporaryFile&release=5

Django doesn't guarantee any consistency, usability or stability of the internal APIs. Use them at your own risk.

On a side note, delete=True is the default: http://docs.python.org/library/tempfile#tempfile.NamedTemporaryFile Just don't specify it and you'll be fine.

comment:2 by Malcolm Tredinnick, 13 years ago

In [16694]:

Clarify the documentation around SQLite and case-sensitive string matching.

This was still causing some confusion, so I rewrote the section in the
database notes to encompass both substring matching and non-ASCII
case-insensitive equality checks, as well as putting in a stronger
callout on the "contains" filter.

Refs #16569.

comment:3 by Malcolm Tredinnick, 13 years ago

(Ignore previous comment; should have gone to #15659.)

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