diff --git a/tgext/crud/controller.py b/tgext/crud/controller.py index 2778f54..f7285dc 100644 --- a/tgext/crud/controller.py +++ b/tgext/crud/controller.py @@ -1,7 +1,7 @@ """ """ import tg -from tg import expose, flash, redirect, tmpl_context, request +from tg import expose, flash, redirect, tmpl_context, request, abort from tg.decorators import without_trailing_slash, with_trailing_slash, before_validate from tg.controllers import RestController @@ -266,7 +266,10 @@ def get_all(self, *args, **kw): if tg.request.response_type == 'application/json': adapt_params_for_pagination(kw, self.pagination_enabled) - count, values = self.table_filler._do_get_provider_count_and_objs(**kw) + try: + count, values = self.table_filler._do_get_provider_count_and_objs(**kw) + except Exception as e: + abort(400, detail=unicode(e)) values = self._dictify(values, length=count) if self.pagination_enabled: values = SmartPaginationCollection(values, count) @@ -280,7 +283,14 @@ def get_all(self, *args, **kw): substring_filters = self.substring_filters adapt_params_for_pagination(kw, self.pagination_enabled) - values = self.table_filler.get_value(substring_filters=substring_filters, **kw) + try: + values = self.table_filler.get_value(substring_filters=substring_filters, **kw) + except Exception as e: + flash(u'Invalid search query "%s": %s' % (request.query_string, e), 'warn') + # Reset all variables to sane defaults + kw = {} + values = [] + self.table_filler.__count__ = 0 if self.pagination_enabled: values = SmartPaginationCollection(values, self.table_filler.__count__) else: