Skip to content

Commit 019b56d

Browse files
committed
Fix issue2551129 - Template not found return 500 and traceback
Handle traceback caused when requested @template is not found. Moved scope of try to include call to self.selectTemplate. Patch provided by Cedric Krier. Additional patch to make this case return 400 error since it is a client caused error. Test case added.
1 parent e572c0c commit 019b56d

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

CHANGES.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ Fixed:
8888
- issue2551128 - Impossible to validate a user with unknown timezone
8989
Raise KeyError when an unrecognized timezones is passed to
9090
pytz. (patch Cedric Krier, test John Rouillard)
91+
- issue2551129 - Template not found return 500
92+
Handle traceback caused when requested @template is not found.
93+
Return 400 error in this condition. (patch Cedric Krier,
94+
additional change and test John Rouillard)
9195

9296
Features:
9397
- issue2550522 - Add 'filter' command to command-line

roundup/cgi/client.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,14 +1863,14 @@ def selectTemplate(self, name, view):
18631863
def renderContext(self):
18641864
""" Return a PageTemplate for the named page
18651865
"""
1866-
tplname = self.selectTemplate(self.classname, self.template)
1867-
1868-
# catch errors so we can handle PT rendering errors more nicely
1869-
args = {
1870-
'ok_message': self._ok_message,
1871-
'error_message': self._error_message
1872-
}
18731866
try:
1867+
tplname = self.selectTemplate(self.classname, self.template)
1868+
1869+
# catch errors so we can handle PT rendering errors more nicely
1870+
args = {
1871+
'ok_message': self._ok_message,
1872+
'error_message': self._error_message
1873+
}
18741874
pt = self.instance.templates.load(tplname)
18751875
# let the template render figure stuff out
18761876
result = pt.render(self, None, None, **args)
@@ -1894,6 +1894,7 @@ def renderContext(self):
18941894
result = result.replace('</body>', s)
18951895
return result
18961896
except templating.NoTemplate as message:
1897+
self.response_code = 400
18971898
return '<strong>%s</strong>'%html_escape(str(message))
18981899
except templating.Unauthorised as message:
18991900
raise Unauthorised(html_escape(str(message)))

test/test_cgi.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,17 @@ def testBackwardsCompat(self):
746746
'name': 'foo.txt', 'type': 'text/plain'}},
747747
[('issue', None, 'files', [('file', '-1')])]))
748748

749+
def testErrorForBadTemplate(self):
750+
form = {}
751+
cl = self.setupClient(form, 'issue', '1', template="broken",
752+
env_addon = {'HTTP_REFERER': 'http://whoami.com/path/'})
753+
out = []
754+
755+
out = cl.renderContext()
756+
757+
self.assertEqual(out, '<strong>No template file exists for templating "issue" with template "broken" (neither "issue.broken" nor "_generic.broken")</strong>')
758+
self.assertEqual(cl.response_code, 400)
759+
749760
def testFormValuePreserveOnError(self):
750761
page_template = """
751762
<html>

0 commit comments

Comments
 (0)