﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
29183	"""cache"" template tag should not render empty strings on failure"	Nicolas Le Manchet	nobody	"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."	Uncategorized	closed	Core (Cache system)	2.0	Normal	invalid	cache, template, memcached, pylibmc		Unreviewed	0	0	0	0	0	0
