mirror of
https://github.com/Hopiu/django-imagekit.git
synced 2026-03-17 05:40:25 +00:00
When Celery CachedFileBackend used with filesystem storage (django.core.files.storage.FileSystemStorage), everything works fine. But there are issues with storages.backends.s3boto3.S3Boto3Storage (and it's fix from #391), as well as with django_s3_storage.storage.S3Storage. Exception was: ``` Traceback (most recent call last): ... File "/src/django-imagekit/imagekit/cachefiles/__init__.py", line 131, in __bool__ existence_required.send(sender=self, file=self) ... File "/libs/utils.py", line 380, in on_existence_required file.generate() File "/src/django-imagekit/imagekit/cachefiles/__init__.py", line 94, in generate self.cachefile_backend.generate(self, force) File "/src/django-imagekit/imagekit/cachefiles/backends.py", line 136, in generate self.schedule_generation(file, force=force) File "/src/django-imagekit/imagekit/cachefiles/backends.py", line 165, in schedule_generation _celery_task.delay(self, file.generator, force=force) ... File "/lib/python3.6/site-packages/kombu/serialization.py", line 221, in dumps payload = encoder(data) File "/lib/python3.6/site-packages/kombu/serialization.py", line 350, in pickle_dumps return dumper(obj, protocol=pickle_protocol) kombu.exceptions.EncodeError: can't pickle _thread._local objects ```
43 lines
1.2 KiB
Python
43 lines
1.2 KiB
Python
"""
|
|
Make sure that the various IK classes can be successfully serialized and
|
|
deserialized. This is important when using IK with Celery.
|
|
|
|
"""
|
|
|
|
from imagekit.cachefiles import ImageCacheFile
|
|
from .imagegenerators import TestSpec
|
|
from .utils import create_photo, pickleback, get_unique_image_file, clear_imagekit_cache
|
|
|
|
|
|
def test_imagespecfield():
|
|
clear_imagekit_cache()
|
|
instance = create_photo('pickletest2.jpg')
|
|
thumbnail = pickleback(instance.thumbnail)
|
|
thumbnail.generate()
|
|
|
|
|
|
def test_circular_ref():
|
|
"""
|
|
A model instance with a spec field in its dict shouldn't raise a KeyError.
|
|
|
|
This corresponds to #234
|
|
|
|
"""
|
|
clear_imagekit_cache()
|
|
instance = create_photo('pickletest3.jpg')
|
|
instance.thumbnail # Cause thumbnail to be added to instance's __dict__
|
|
pickleback(instance)
|
|
|
|
|
|
def test_cachefiles():
|
|
clear_imagekit_cache()
|
|
spec = TestSpec(source=get_unique_image_file())
|
|
file = ImageCacheFile(spec)
|
|
file.url
|
|
# remove link to file from spec source generator
|
|
# test __getstate__ of ImageCacheFile
|
|
file.generator.source = None
|
|
restored_file = pickleback(file)
|
|
assert file is not restored_file
|
|
# Assertion for #437 and #451
|
|
assert file.storage is restored_file.storage
|