Fix reading empty file or seeking past end of file for s3 backend #549
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
This PR fixes seeking past the end of an s3 file, which I broke in #495. E.g. this will now work instead of raising a boto error:
file.tell()
will then give the current position as the actual end of the file, andf.read()
will returnb''
.This also fixes opening an empty file for reading, as reported in #548 -- that turns out to be a special case of seeking past the end of a file being broken.
The reason this wasn't working before is that moto doesn't return the same API response as real S3 when requesting an invalid range with GetObject, as reported here. We were correctly handling moto-style responses but failing to handle real-S3-style responses. So this PR:
_get
in the relevant tests to return real-S3-style responses. This mock could be removed when the upstream bug in moto is fixedFixes #548
Checklist
Before you create the PR, please make sure you have: