Merge pull request #751 from akolpakov/issue_750
#750 CompilerFilter fails with UnicodeDecodeError when cache is used
This commit is contained in:
commit
f5c1469c8e
@ -221,7 +221,7 @@ class CachedCompilerFilter(CompilerFilter):
|
|||||||
key = self.get_cache_key()
|
key = self.get_cache_key()
|
||||||
data = cache.get(key)
|
data = cache.get(key)
|
||||||
if data is not None:
|
if data is not None:
|
||||||
return data
|
return smart_text(data)
|
||||||
filtered = super(CachedCompilerFilter, self).input(**kwargs)
|
filtered = super(CachedCompilerFilter, self).input(**kwargs)
|
||||||
cache.set(key, filtered, settings.COMPRESS_REBUILD_TIMEOUT)
|
cache.set(key, filtered, settings.COMPRESS_REBUILD_TIMEOUT)
|
||||||
return filtered
|
return filtered
|
||||||
|
@ -3,8 +3,10 @@ from collections import defaultdict
|
|||||||
import io
|
import io
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import mock
|
||||||
|
|
||||||
from django.utils import six
|
from django.utils import six
|
||||||
|
from django.utils.encoding import smart_text
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.test.utils import override_settings
|
from django.test.utils import override_settings
|
||||||
|
|
||||||
@ -112,6 +114,15 @@ class PrecompilerTestCase(TestCase):
|
|||||||
self.assertEqual("body { color:#990; }", compiler.input())
|
self.assertEqual("body { color:#990; }", compiler.input())
|
||||||
self.assertIsNotNone(compiler.infile) # Not cached
|
self.assertIsNotNone(compiler.infile) # Not cached
|
||||||
|
|
||||||
|
@mock.patch('django.core.cache.backends.locmem.LocMemCache.get')
|
||||||
|
def test_precompiler_cache_issue750(self, mock_cache):
|
||||||
|
# emulate memcached and return string
|
||||||
|
mock_cache.side_effect = (lambda key: str("body { color:#990; }"))
|
||||||
|
command = '%s %s -f {infile} -o {outfile}' % (sys.executable, self.test_precompiler)
|
||||||
|
compiler = CachedCompilerFilter(command=command, **self.cached_precompiler_args)
|
||||||
|
self.assertEqual("body { color:#990; }", compiler.input())
|
||||||
|
self.assertEqual(type(compiler.input()), type(smart_text("body { color:#990; }")))
|
||||||
|
|
||||||
def test_precompiler_not_cacheable(self):
|
def test_precompiler_not_cacheable(self):
|
||||||
command = '%s %s -f {infile} -o {outfile}' % (sys.executable, self.test_precompiler)
|
command = '%s %s -f {infile} -o {outfile}' % (sys.executable, self.test_precompiler)
|
||||||
self.cached_precompiler_args['mimetype'] = 'text/different'
|
self.cached_precompiler_args['mimetype'] = 'text/different'
|
||||||
|
Loading…
Reference in New Issue
Block a user