Opened 7 years ago

Closed 7 years ago

Last modified 7 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


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:
from django.core.files.temp import NamedTemporaryFile

img_temp = NamedTemporaryFile(delete=True)
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:

if == 'nt':
in which case NamedTemporaryFile = TemporaryFile as defined above it.

However, according to NamedTemporaryFile should be able to handle delete as well!

A solution would be to define NamedTemporaryFile as follows:

class NamedTemporaryFile(TemporaryFile):

def init(self, kwargs):

kwargs.pop('delete', True) # TODO: handle this delete flag

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

Change History (3)

comment:1 Changed 7 years ago by Aymeric Augustin

Has patch: unset
Resolution: invalid
Status: newclosed

NamedTemporaryFile isn't a public API — there isn't any reference to this class in the documentation:

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: Just don't specify it and you'll be fine.

comment:2 Changed 7 years ago by Malcolm Tredinnick

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 Changed 7 years ago by Malcolm Tredinnick

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

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