mirror of
https://github.com/Hopiu/django-imagekit.git
synced 2026-03-16 21:30:23 +00:00
Merge pull request #469 from matthewwithanm/fix-image-cachefile-serializtion
Fix pickle serialization for ImageCacheFile
This commit is contained in:
commit
6f7de35f79
3 changed files with 25 additions and 1 deletions
|
|
@ -185,6 +185,11 @@ Or, in Python:
|
|||
def on_source_saved(self, file):
|
||||
file.generate()
|
||||
|
||||
.. note::
|
||||
|
||||
If you use custom storage backend for some specs,
|
||||
(storage passed to the field different than configured one)
|
||||
it's required the storage to be pickleable
|
||||
|
||||
|
||||
__ https://pypi.python.org/pypi/django-celery
|
||||
|
|
|
|||
|
|
@ -144,8 +144,24 @@ class ImageCacheFile(BaseIKFile, ImageFile):
|
|||
# file is hidden link to "file" attribute
|
||||
state.pop('_file', None)
|
||||
|
||||
# remove storage from state as some non-FileSystemStorage can't be
|
||||
# pickled
|
||||
settings_storage = get_singleton(
|
||||
settings.IMAGEKIT_DEFAULT_FILE_STORAGE,
|
||||
'file storage backend'
|
||||
)
|
||||
if state['storage'] == settings_storage:
|
||||
state.pop('storage')
|
||||
return state
|
||||
|
||||
def __setstate__(self, state):
|
||||
if 'storage' not in state:
|
||||
state['storage'] = get_singleton(
|
||||
settings.IMAGEKIT_DEFAULT_FILE_STORAGE,
|
||||
'file storage backend'
|
||||
)
|
||||
self.__dict__.update(state)
|
||||
|
||||
def __nonzero__(self):
|
||||
# Python 2 compatibility
|
||||
return self.__bool__()
|
||||
|
|
|
|||
|
|
@ -37,4 +37,7 @@ def test_cachefiles():
|
|||
# remove link to file from spec source generator
|
||||
# test __getstate__ of ImageCacheFile
|
||||
file.generator.source = None
|
||||
pickleback(file)
|
||||
restored_file = pickleback(file)
|
||||
assert file is not restored_file
|
||||
# Assertion for #437 and #451
|
||||
assert file.storage is restored_file.storage
|
||||
|
|
|
|||
Loading…
Reference in a new issue