SmileyChris / easy-thumbnails

Easy thumbnails for Django
http://easy-thumbnails.readthedocs.org/
BSD 3-Clause "New" or "Revised" License
1.39k stars 319 forks source link

Pickle problem #476

Closed aarcro closed 7 years ago

aarcro commented 7 years ago

After a trip through the pickle/unpickle machine the ThumbnailerField fields on my models can no longer generate thumbnails.

I'm using django-cacheops which pickles whole objects into the cache to reduce query duplication, so I'd really like to be able to pickle models with ThumbnailerFields

>>> p.photo
<ThumbnailerFieldFile: post/Daffy_duck2_sAf8Zs8.jpg>
>>> p.photo['app_display']
<ThumbnailFile: thumbs/post/Daffy_duck2_sAf8Zs8.jpg.1242x1242_q71.jpg>
>>> p.photo['app_display'].url
'/media/thumbs/post/Daffy_duck2_sAf8Zs8.jpg.1242x1242_q71.jpg'
>>> import pickle
>>> r = pickle.loads(pickle.dumps(p))
>>> r == p
True
>>> r.photo
<ThumbnailerFieldFile: post/Daffy_duck2_sAf8Zs8.jpg>
>>> r.photo == p.photo
True
>>> r.photo['app_display']
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python3.6/site-packages/easy_thumbnails/files.py", line 339, in __getitem__
    options = aliases.get(alias, target=self.alias_target)
AttributeError: 'ThumbnailerFieldFile' object has no attribute 'alias_target'
>>> r.photo == p.photo
True
>>> r.photo.__dict__ == p.photo.__dict__
False
>>> pd(r.photo)
{'_committed': True,
 '_file': None,
 'closed': False,
 'field': <easy_thumbnails.fields.ThumbnailerField: photo>,
 'instance': <Post: Daffy Duck on 2017-10-09 20:01:28+00:00>,
 'name': 'post/Daffy_duck2_sAf8Zs8.jpg',
 'storage': <django.core.files.storage.DefaultStorage object at 0x7f2dc0036dd8>}
>>> pd(p.photo)
{'_committed': True,
 '_file': None,
 'alias_target': <ThumbnailerFieldFile: post/Daffy_duck2_sAf8Zs8.jpg>,
 'field': <easy_thumbnails.fields.ThumbnailerField: photo>,
 'generate': True,
 'instance': <Post: Daffy Duck on 2017-10-09 20:01:28+00:00>,
 'name': 'post/Daffy_duck2_sAf8Zs8.jpg',
 'remote_source': False,
 'source_storage': <django.core.files.storage.DefaultStorage object at 0x7f2dc0036dd8>,
 'storage': <django.core.files.storage.DefaultStorage object at 0x7f2dc0036dd8>,
 'thumbnail_basedir': 'thumbs',
 'thumbnail_check_cache_miss': False,
 'thumbnail_extension': 'jpg',
 'thumbnail_high_resolution': False,
 'thumbnail_highres_infix': '@2x',
 'thumbnail_namer': 'easy_thumbnails.namers.default',
 'thumbnail_prefix': '',
 'thumbnail_preserve_extensions': None,
 'thumbnail_quality': 85,
 'thumbnail_storage': <easy_thumbnails.storage.ThumbnailDefaultStorage object at 0x7f2dbafb8ac8>,
 'thumbnail_subdir': '',
 'thumbnail_transparency_extension': 'png'}
>>> 
aarcro commented 7 years ago

FYI Originally opened the issue with cacheops https://github.com/Suor/django-cacheops/issues/253