Closed kalombos closed 5 years ago
I'm having this issue with a Flask app, but using standard SQLAlchemy (not the Flask version). I can reproduce the error from the Python console, it happens when calling the .output_result() method.
In the JS it's this:
table = $('#inventory').DataTable({ "processing": true, "serverside": true, "ajax": "{{ url_for('dtinventory') }}" })
In the app I define the columns with ColumnDT(Table.columnname) like in the examples. I printed out request.args.todict() and it shows {'': u'1498955924433'}. The result gives me KeyError: 'draw'.
What is this 'draw' and how is that supposed to be passed? I can't find any examples using "ajax" you can even define specific parameters. I assume 'draw' probably has something to do with setting the number of rows to return?
I'm using DataTables JS version 1.10.13, SQLAlchemy 1.1.6, and sqlalchemy-datatables 1.2.0.
And kalombos, nice cat. :)
TBH I am not sure what the draw parameter does. Perhaps we should put a default value. Something like this should do it:
output['draw'] = str(int(self.params['draw']))
to
output['draw'] = str(int(self.params.get('draw',1))
@magykjames were you able to find a solution? having the same issue
Don't know if this helps but I found I got this error when I was making requests to the data endpoint instead of letting the Datatables object make the ajax request. The Datatables JS will add in all the necessary params for output_result()
I receive this error every now and then on my site https://openmultilaterals.org/. It happens with this call https://github.com/openstate/multilateral-organisations/blob/master/app/routes.py#L571.
I guess the suggested PR of @kalombos or the fix from @tdamsma would solve it?
@siccovansas, I kind of forgot about this, thanks for the reminder. Nice site by the way
Thanks for the fix everyone! Works like a charm :)
If i do not pass "draw" param in get request in flask example i get a 500 error. I can make a PR to fix it something like this:
https://github.com/Pegase745/sqlalchemy-datatables/blob/master/datatables/__init__.py#L241
Should i make it?