Skip to content

Commit

Permalink
matthewwithanm#473 need to change the order here, first populate "sel…
Browse files Browse the repository at this point in the history
…f.file", then seek to start of file handle, and then "self.storage.save" (which will result in a closed file handle, from which we can no longer seek nor read)
  • Loading branch information
agrelle committed Jan 31, 2021
1 parent 4cf8bd5 commit 6c4c108
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions imagekit/cachefiles/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,16 @@ def _generate(self):
# Generate the file
content = generate(self.generator)

actual_name = self.storage.save(self.name, content)

# We're going to reuse the generated file, so we need to reset the pointer.
content.seek(0)

# Store the generated file. If we don't do this, the next time the
# "file" attribute is accessed, it will result in a call to the storage
# backend (in ``BaseIKFile._get_file``). Since we already have the
# contents of the file, what would the point of that be?
self.file = File(content)

# We're going to reuse the generated file, so we need to reset the pointer.
content.seek(0)
actual_name = self.storage.save(self.name, content)

if actual_name != self.name:
get_logger().warning(
'The storage backend %s did not save the file with the'
Expand Down

0 comments on commit 6c4c108

Please sign in to comment.