﻿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
21189	Correct the usage of bare except clauses in django's source	Berker Peksag	nobody	"While I was working on #6834, I found this piece of code in django/template/loader_tags.py:

{{{#!python

def render(self, context):
    try:
        template = self.template.resolve(context)
        # Does this quack like a Template?
        if not callable(getattr(template, 'render', None)):
            # If not, we'll try get_template
            template = get_template(template)
        values = {
            name: var.resolve(context)
            for name, var in six.iteritems(self.extra_context)
        }
        if self.isolated_context:
            return template.render(context.new(values))
        with context.push(**values):
            return template.render(context)
    except:
        if settings.TEMPLATE_DEBUG:
            raise
        return ''
}}}

See from GitHub: https://github.com/django/django/blob/master/django/template/loader_tags.py#L146

I change the bare except in line 146 to:

{{{#!python
except (TemplateDoesNotExist, TemplateSyntaxError):
}}}

and ran the test suite:

{{{#!sh
./runtests.py --settings=test_sqlite template_tests
}}}

Here is the output: https://gist.github.com/berkerpeksag/ab84b067a552951abd9c

So, is the usage of bare except correct?

Thanks!"	Bug	closed	Core (Other)	dev	Normal	fixed		Berker Peksag bmispelon@…	Accepted	0	0	0	0	0	0
