﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
36975	SimpleUploadedFile cannot be re-opened	Denis Washington	Vishy Algo	"=== Summary

When a `SimpleUploadedFile` is closed, it calls `close()` on the underlying `BytesIO`, which means that the next call to `open()` fails (`ValueError: I/O operation on closed file.`). This is unlike the conceptually similar `ContentFile`, which explicitly overrides `close()` to do nothing, avoiding this issue.

=== How to Reproduce

The following script reproduces the issue:

{{{#!python
from django.core.files.base import ContentFile
from django.core.files.uploadedfile import SimpleUploadedFile


def read_twice(file):
    with file.open() as f:
        print(f.read())
    with file.open() as f:
        print(f.read())


# Works as expected
read_twice(ContentFile(b""test data""))

# ValueError: I/O operation on closed file.
read_twice(SimpleUploadedFile(""test.txt"", b""test data""))
}}}

=== Expected Behavior

`SimpleUploadedFile` should follow `ContentFile` in making `close()` a no-op.

Ideally, the same should be done by its superclass `InMemoryUploadedFile`, at least if its `file` is a `BytesIO` or `StringIO`. (Skipping closing unconditionally could be risky here because the init method accepts any file-like object in principle.)
"	Bug	closed	File uploads/storage	6.0	Normal	duplicate			Unreviewed	0	0	0	0	0	0
