#29183: "cache" template tag should not render empty strings on failure -------------------------------------+------------------------------------- Reporter: NicolasLM | Owner: nobody Type: | Status: new Uncategorized | Component: Core | Version: 2.0 (Cache system) | Keywords: cache, template, Severity: Normal | memcached, pylibmc Triage Stage: | Has patch: 0 Unreviewed | Needs documentation: 0 | Needs tests: 0 Patch needs improvement: 0 | Easy pickings: 1 UI/UX: 0 | -------------------------------------+------------------------------------- The cache template tag renders an empty string when a connection errors happens while fetching from the cache.
I believe that the "cache" template tag should try to fetch from the cache, but fall back to being a noop in case of error. **Example:** An included template contains an expensive calculation wrapped in a cache tag: {{{ <div class="content"> {% cache 600 cleaned_article article.id %}{{ article.content | clean_article | safe }}{% endcache %} </div> }}} If any error happens while fetching from the cache, the included template is rendered as an empty string and the following warning is printed in logs: {{{ [2018-03-03 17:36:08,140 WARNI waitress django.template] Exception raised while rendering {% include %} for template 'reader/home.html'. Empty string rendered instead. Traceback (most recent call last): File "/usr/local/lib/python3.6/site- packages/django/template/loader_tags.py", line 194, in render return template.render(context) File "/usr/local/lib/python3.6/site-packages/django/template/base.py", line 177, in render return self._render(context) File "/usr/local/lib/python3.6/site-packages/django/test/utils.py", line 98, in instrumented_test_render return self.nodelist.render(context) File "/usr/local/lib/python3.6/site-packages/django/template/base.py", line 943, in render bit = node.render_annotated(context) File "/usr/local/lib/python3.6/site-packages/django/template/base.py", line 910, in render_annotated return self.render(context) File "/usr/local/lib/python3.6/site- packages/django/template/defaulttags.py", line 211, in render nodelist.append(node.render_annotated(context)) File "/usr/local/lib/python3.6/site-packages/django/template/base.py", line 910, in render_annotated return self.render(context) File "/usr/local/lib/python3.6/site- packages/django/templatetags/cache.py", line 45, in render value = fragment_cache.get(cache_key) File "/usr/local/lib/python3.6/site- packages/django/core/cache/backends/memcached.py", line 73, in get val = self._cache.get(key) pylibmc.ConnectionError: error 3 from memcached_get(:1:template.cache.cleaned_articl): (0x7faf5c0cee70) CONNECTION FAILURE, ::rec() returned zero, server has disconnected, host: memcached:11211 -> libmemcached/io.cc:484 }}} Cache settings: {{{ CACHES = { 'default': { 'BACKEND': 'django.core.cache.backends.memcached.PyLibMCCache', 'TIMEOUT': 24 * 60 * 60, 'LOCATION': 'memcached:11211', 'OPTIONS': { 'binary': True, 'behaviors': { 'no_block': True, 'tcp_nodelay': True, 'tcp_keepalive': True, 'connect_timeout': 2000, # ms 'send_timeout': 750 * 1000, # us 'receive_timeout': 750 * 1000, # us '_poll_timeout': 2000, # ms 'ketama': True, 'remove_failed': 1, 'retry_timeout': 2, 'dead_timeout': 30, } } } } }}} **Additional information:** Django 2.0.2 Python 3.6.4 Linux 4.9.82 Both the Django application and Memcached run on Docker containers on the same host. The error happens after a restart of Memcached (but no restart of the Django container) because pylibmc reuses connections between requests and it cannot detect that connections should be discarded because of the Docker userland proxy. -- Ticket URL: <https://code.djangoproject.com/ticket/29183> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/052.b83d3572b444bee805e6ff9294e2b0b9%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.