Error occurs, but result: "OK" returned.

Issue #26 resolved
RC Johnson created an issue

If an exception is raised, and caught by DataTableMixin, line 222:

 except Exception as e:
            logger.exception(str(e))

            if settings.DEBUG:
                import sys
                from django.views.debug import ExceptionReporter
                reporter = ExceptionReporter(None, *sys.exc_info())
                text = "\n" + reporter.get_traceback_text()
            else:
                text = "\nAn error occured while processing an AJAX request."

            if self.pre_camel_case_notation:
                ret = {'result': 'error',
                       'sError': text,
                       'text': text,
                       'aaData': [],
                       'sEcho': int(self._querydict.get('sEcho', 0)),
                       'iTotalRecords': 0,
                       'iTotalDisplayRecords': 0, }
            else:
                ret = {'error': text,
                       'data': [],
                       'recordsTotal': 0,
                       'recordsFiltered': 0,
                       'draw': int(self._querydict.get('draw', 0))}
        return ret

The JSON returned when self.pre_camel_case_notation is False does not include result: 'error' so JSONResponseMixin includes result: 'OK' in the response at line 56:

if 'result' not in response:
                    response['result'] = 'ok'

This prevents the DataTable from displaying any error message, even though the underlying JSON clearly includes an error.

I believe the fix to this is to include result: 'error' in DataTableMixin, and I'm happy to contribute a patch if you feel this is a correct solution.

Comments (3)

  1. Maciej Wisniowski repo owner

    This is a bit strange as there is no result value defined in DataTables API for ServerSide processing (https://datatables.net/manual/server-side). result is just an extra parameter returned by the JSON mixin. For datatables it should be enough to see error key in returned data that indicates that something has failed.

    I'd have to check it though. Which version of DataTables do you use?

  2. Log in to comment