devilry / devilry-django

Devilry project main repository
http://devilry.org
BSD 3-Clause "New" or "Revised" License
51 stars 24 forks source link

django-storages 1.14.2+ compatibility #1298

Closed torgeirl closed 2 months ago

torgeirl commented 4 months ago

ZIP steaming from a S3 backend fails with django-storages 1.14.2 (or newer). Looks to be related with an issue solved in django-storages v1.14.2.

ValueError: Cannot reopen file with a new mode.
  File "gunicorn/http/wsgi.py", line 35, in __getitem__
    data = self.filelike.read(self.blksize)
  File "to_file_like_obj.py", line 30, in read
    return base().join(
  File "to_file_like_obj.py", line 15, in up_to_iter
    chunk = next(it)
  File "stream_zip.py", line 716, in stream_zip
    yield from evenly_sized(zipped_chunks)
  File "stream_zip.py", line 102, in evenly_sized
    block = b''.join(up_to(chunk_size))
  File "stream_zip.py", line 91, in up_to
    chunk = next(it)
  File "stream_zip.py", line 645, in get_zipped_chunks_uneven
    central_directory_header_entry, name_encoded, extra = yield from data_func(compression, aes_size_increase, aes_flags, name_encoded, mod_at_ms_dos, mod_at_unix_extra, aes_extra, external_attr, uncompressed_size, crc_32, crc_32_mask, _get_compress_obj, encryption_func, evenly_sized(chunks))
  File "stream_zip.py", line 294, in _zip_32_local_header_and_data
    uncompressed_size, raw_compressed_size, crc_32 = yield from encryption_func(_zip_data(
  File "stream_zip.py", line 173, in _encrypt_dummy
    for chunk in chunks_with_return:
  File "stream_zip.py", line 167, in with_return_value
    return_value = yield from gen
  File "stream_zip.py", line 331, in _zip_data
    for chunk in chunks:
  File "stream_zip.py", line 102, in evenly_sized
    block = b''.join(up_to(chunk_size))
  File "stream_zip.py", line 91, in up_to
    chunk = next(it)
  File "devilry/devilry_compressionutil/backends/backends_base.py", line 245, in contents
    with file_object.file.open('r') as f:
  File "storages/backends/s3.py", line 153, in open
    raise ValueError("Cannot reopen file with a new mode.")
Levijatan commented 3 months ago

Change the with file_object.file.open('r') as f: to with file_object.file.open() as f: since it failes on the check in django-storages. That check is only applied when mode is specified. And it looks like S3Files are using 'rb' by default. 1afaede

espenak commented 2 months ago

Fixed