Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't reopen image files that are hosted externally #1605

Merged
merged 3 commits into from
Aug 26, 2015

Conversation

kaedroho
Copy link
Contributor

Fixes #1397

This caused crashes on the chooser upload and image edit views.

Some image hosting backends don't allow files to be reopened once closed and will crash with ValueError("The file cannot be reopened.") if you tried it.

I've seen this issue in the following third-party storage backends:

  • offsite_storage.storages.S3MediaStorage
  • storages.backends.s3.S3Storage
  • storages.backends.apache_libcloud.LibCloudStorage

This PR modifies the Image.get_willow_image method to make it get a fresh File instance if it detects that it is reopening a file that is externally hosted. It also adds some utils to allow us to test against a dummy external storage backend.

Testing the following with an external image backend:
 - Uploading through image chooser (fails)
 - Visiting the edit page of an image with a null file_size (fails)
 - Editing an image, changing the image file
 - Adding a new image

The latter two do not fail, I thought I'd add them to reduce risk of regressions in the future
if self.is_stored_locally():
self.file.open('rb')
else:
# Some external storage backends don't allow reopening
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it might be simpler to just get a fresh File object for local files as well

@kaedroho kaedroho added this to the 1.1 milestone Aug 14, 2015
@sixpearls
Copy link
Contributor

I was seeing this when using my FTP based remote storage, as well. I was mainly testing using the single image uploader. I noticed that the renditions in the list view were generated fine, but it crashed when trying to generate the renditions for the detail view. If I get the chance, I can try playing with it in my dev environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error Uploading an Image
4 participants