-
Notifications
You must be signed in to change notification settings - Fork 276
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
Fix image cachefile serializtion #437
Fix image cachefile serializtion #437
Conversation
From the traceback I see that the problem is that In From one point of view every custom storage need to behave as close to Django builtin storage in order to be used interchangeably, but the reality is that only the basic operations are the same. At second look in order to provide smaller pickle representations we need to tune In this case a better approach can be changing What you think about that? |
@vstoykov thanks, your solution is much better and this really explains the issue. But I'm not sure how it should act in case of custom storage (i.e. passed to |
Yep that will be a problem and probably separate issues need to be made for Probably we also need to add in documentation that wen non default storage is used (storage passed to the field different than configured one) it's required the storage to be pickleable if celery or rq backend are used (which I hope that is not so common scenario). Can you try to change the PR (or create a new one) with modified |
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 ```
Thanks, now it looks better and working |
@ron8mcr thank you very much for your work on this issue. One last thing. Can you try to add a test case that will pickle (see if there are test that will test pickleability) of ImageCacheFile? |
@vstoykov, there are few test cases already |
Yes there are test cases for cache files but there is no test that will ensure that if The change in this merge request will ensure that if the storage is default storage than there is no need to pickle it, and if there is no storage to restore then use default storage (which is singleton). Then if checked with
Without your change this assertion should fail. |
@ron8mcr are you still interested this to be merged? If not I can make tests for it when I have some time available. Still I will be very glad if you can make the tests for this issue? Thanks in advance. |
@vstoykov sorry for late response. Yes, I'm interested in, but have not enough time to finish it. I'll do my best to finish on this weekend |
This pr closes #451 |
@ron8mcr any updates on this PR? Thank you :) |
Fix pickle serialization for ImageCacheFile
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 withdjango_s3_storage.storage.S3Storage
.I didn't debug it to the real core reason, but seem like
pickle
serializer used for celery task can't serializeImageCacheFile.storage
. So passing instance ofImageCacheFile
was replaced with passing its generator without storage attrs, which serializes without any errorsIt seems like a hacky solution, but it works
Exception was: