matthewwithanm / django-imagekit

Automated image processing for Django. Currently v4.0
http://django-imagekit.rtfd.org/
BSD 3-Clause "New" or "Revised" License
2.26k stars 276 forks source link

Async cachefile backends does not work with JustInTime strategy #434

Closed ron8mcr closed 6 years ago

ron8mcr commented 6 years ago

To reproduce set: IMAGEKIT_DEFAULT_CACHEFILE_BACKEND = 'imagekit.cachefiles.backends.RQ' or IMAGEKIT_DEFAULT_CACHEFILE_BACKEND = 'imagekit.cachefiles.backends.Celery' and IMAGEKIT_DEFAULT_CACHEFILE_STRATEGY = 'imagekit.cachefiles.strategies.JustInTime'

For RQ backend it fails with maximum recursion depth exceeded in comparison, and for celery it generates a lot of tasks.

Seem like issue is for _generate_file function params. It signature is:

def _generate_file(backend, file, force=False)

So when code tries to serialize file param, both celery and rq are trying to get a representation of file which calls file generation which calls representation which calls generation...

Simplest solution is to update __repr__ method of ImageCacheFile. Original django implementation is (note for self or "None")

    def __repr__(self):
        return force_str("<%s: %s>" % (
            self.__class__.__name__, self or "None")
        )

And working solution is

    def __repr__(self):
        return force_str("<%s: %s>" % (
            self.__class__.__name__, self if self.name else "None")
        )
vstoykov commented 6 years ago

I'm closing the issue. The fix will be released in the next version.

vstoykov commented 6 years ago

Sorry for the delay. I released the new version. with fix for this issue.

Probably I should have pinged you about #437 (if you are still interested in it) before releasing this bugfix release to be also included but we can put it in the next one.