From 66e1f35205027e4974a4fe04cc599f8d48a35709 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ionel=20Cristian=20M=C4=83rie=C8=99?= Date: Tue, 27 Aug 2013 13:50:38 +0300 Subject: [PATCH] Fix "silent" error handling in the TableData.__init__ to prepend the complete traceback and show original exception for Python 2.x. Previously it was impossible to debug query-time issues with django_tables2. --- django_tables2/tables.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/django_tables2/tables.py b/django_tables2/tables.py index 1b884e1..6d2785d 100644 --- a/django_tables2/tables.py +++ b/django_tables2/tables.py @@ -6,6 +6,7 @@ from .rows import BoundRows from .utils import (Accessor, AttributeDict, build_request, cached_property, OrderBy, OrderByTuple, segment, Sequence) import copy +import sys from django.core.paginator import Paginator from django.db.models.fields import FieldDoesNotExist from django.utils.datastructures import SortedDict @@ -36,10 +37,19 @@ class TableData(object): else: try: self.list = list(data) - except: - raise ValueError('data must be QuerySet-like (have count and ' - 'order_by) or support list(data) -- %s has ' - 'neither' % type(data).__name__) + except Exception as ex: + if six.PY3: + raise ValueError( + 'data must be QuerySet-like (have count and ' + 'order_by) or support list(data) -- %s has ' + 'neither' % type(data).__name__ + ) + else: + raise ValueError, ValueError( + 'data must be QuerySet-like (have count and ' + 'order_by) or support list(data) -- %s has ' + 'neither. Original exception: %s' % (type(data).__name__, ex) + ), sys.exc_info()[2] def __len__(self): if not hasattr(self, "_length"):