django-storages icon indicating copy to clipboard operation
django-storages copied to clipboard

s3: Fix newline handling for text-mode files

Open craigds opened this issue 1 year ago • 3 comments
trafficstars

This fixes the newline issue at #1351. Files open in text mode (r) now get newline handling consistent with other python file-like objects.

run these specific tests with

tox -e py3.10-django4.2 -- tests/test_s3.py -k newlines

craigds avatar Feb 13 '24 19:02 craigds

Thanks @skim618 for finishing this off

craigds avatar Feb 14 '24 20:02 craigds

There were two possible ways of doing this:

  1. Change the initialization of self._file as a NamedTemporaryFile instead of spooled, so we can reopen the file with the correct mode after the contents have been downloaded.
  2. Wrap the underlying self._file's binary object with TextIOWrapper

The changes in this PR implement (2).

self._force_mode has been removed, as this change will now correctly read the file with the right mode (Hence not needing to decode a binary when given "r"). The relevant test(s) has been moved down to the S3 test class, so we can correctly test the storage.save() and storage.open() and flow and thus test the S3File._get_file method correctly.

skim618 avatar Feb 14 '24 21:02 skim618

This change looks good but tests are failing. Is this due to 3.7 not being dropped yet? Once I release the next version the intent is to drop that.

jschneier avatar Feb 16 '24 17:02 jschneier

yes, looks like moto dropped 3.7 support: https://github.com/getmoto/moto/commit/2fd5e800e4aab49a69856fa71bccf898d541a64a

I've fixed the tests by undoing my previous moto upgrade and instead pinning to <5 so the tests will run

craigds avatar Mar 11 '24 23:03 craigds

are those gcloud failures expected? I also get them locally. Seems unrelated to the changes in this PR though

craigds avatar Mar 11 '24 23:03 craigds

are those gcloud failures expected? I also get them locally. Seems unrelated to the changes in this PR though

Seems like a breaking change related to a google cloud dependency.

I'm moving your moto fix and that to a separate PR so I can unblock everything else. Thanks for flagging.

jschneier avatar Mar 15 '24 22:03 jschneier

This actually also exposed a bug in Google Cloud Storage handling of gzip files. I was looking into who wrote the tests in such a confusing way and of course it was...me.

jschneier avatar Mar 15 '24 23:03 jschneier

Alright we are back to green, go ahead and rebase. And thanks again.

jschneier avatar Mar 15 '24 23:03 jschneier

Moved this to #1381

jschneier avatar Apr 21 '24 03:04 jschneier