jschneier / django-storages

https://django-storages.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
2.7k stars 847 forks source link

[s3] Fix newlines test for python 3.11 and above #1400

Closed skim618 closed 2 months ago

skim618 commented 2 months ago

Fixes https://github.com/jschneier/django-storages/pull/1381 CI Failures for Python 3.11 and above

SpooledTemporaryFile introduced new changes in 3.11 (https://docs.python.org/3/library/tempfile.html) It now fully implements the io.BufferedIOBase and io.TextIOBase abstract base classes allowing the file to be readable in the mode that it was specified (without accessing the underlying ._file object).

It seems like wrapping the underlying ._file is forbidden for versions 3.11 and higher (results in the ValueError) Having two have separate methods for different versions isn't the prettiest fix but should suffice.