0001-json-prototype-show-errors-on-rendering-34738.patch
combo/data/models.py | ||
---|---|---|
1266 | 1266 |
if self.force_async and not context.get('synchronous'): |
1267 | 1267 |
raise NothingInCacheException() |
1268 | 1268 |
if self.template_string: |
1269 |
tmpl = engines['django'].from_string(self.template_string) |
|
1270 | 1269 |
context.update(self.get_cell_extra_context(context)) |
1271 |
return tmpl.render(context, context.get('request')) |
|
1270 |
try: |
|
1271 |
tmpl = engines['django'].from_string(self.template_string) |
|
1272 |
return tmpl.render(context, context.get('request')) |
|
1273 |
except Exception as e: |
|
1274 |
return '%r' % e |
|
1272 | 1275 |
return super(JsonCellBase, self).render(context) |
1273 | 1276 | |
1274 | 1277 |
tests/test_cells.py | ||
---|---|---|
291 | 291 |
assert context['json_status'] == 200 |
292 | 292 |
assert context['json_error'] == 'invalid_json' |
293 | 293 | |
294 |
with mock.patch('combo.utils.requests.get') as requests_get: |
|
295 |
data = {'data': [{'url': 'http://a.b', 'text': 'xxx'}]} |
|
296 |
requests_get.return_value = mock.Mock(content=json.dumps(data), status_code=200) |
|
297 |
cell.url = 'http://test6' |
|
298 |
cell.template_string = '{% syntax|error %}' |
|
299 |
result = cell.render({'synchronous': True}) |
|
300 |
assert 'TemplateSyntaxError' in result |
|
301 | ||
294 | 302 |
# URL is a template, using [variables] |
295 | 303 |
cell.cache_duration = 10 |
296 | 304 |
data = {'data': [{'url': 'xxx', 'text': 'xxx'}]} |
297 |
- |