Error occurs, but result: "OK" returned.
Issue #26
resolved
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)
-
repo owner -
reporter We're currently using 1.10.12.
-
repo owner - changed status to resolved
fixed issue
#26; added release notes 1.13.2→ <<cset cd72d593f9ba>>
- Log in to comment
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?