morlandi / django-ajax-datatable

A Django app which provides the integration of a Django project with the jQuery Javascript library DataTables.net
MIT License
215 stars 65 forks source link

GET request sent when retrieving row details raise a "Request line is too large" JS error #114

Open GGosseyn opened 1 year ago

GGosseyn commented 1 year ago

Hello, I use Django 3.2.15 and django-ajax-datatables 4.3.0.

I have a datatable with pre-filters which values are transmitted to the get_initial_queryset method. When I expand the row details, a GET request, containing all the filters values (which can be numerous), is sent to the server (to the render_row_details() method).

_Note: It seems that the 'extra_data' is delivered to the render_rowdetails() method since v4.2.0.

It isn't a problem in the development environment, as we have a limited amount of data in the filter values, but in PRODUCTION, we have a lot more. So, the GET request size limit is reached (around 2K chars).

As I tried to get a solution or a workaround, I noted that in the django-ajax-datatables code, the GET or POST http methods seems to be supported indifferently. So, as the POST method has no size limitation, I made a modification in my development environment in the file ajax_datatable/static/ajax_datatable/js/utils.js, at line 290 (still the same line in the master branch of the Github repo: https://github.com/morlandi/django-ajax-datatable/blob/master/ajax_datatable/static/ajax_datatable/js/utils.js). I just added the http method type being POST, as follow:

284:             $.ajax({
285:                 url: url,
286:                 // data: {
287:                 //     action: 'details',
288:                 //     pk: rowData['pk']
289:                 // },
290: +               type: 'POST',
291:                 data: data,
292:                 dataType: 'json',
293:                 success: function(json) {

It tested and validated it in PRODUCTION and it works like a charm. But I didn't perform extensive tests on every aspect of the django-ajax-datatables functionnalities, so I cannot guarantee it has no side effect at this point.

Do you think that it could be a solution on my issue and that it could be beneficial for other users of the django-ajax-datatables software ? If the answer is positive, could this be incorporated in a future version of the software, as for now, I patched my version locally, which is not very clean, waiting for a more permanent solution.

Regards, Olivier.

morlandi commented 1 year ago

Thank you @GGosseyn .. I think you can safely go ahead with POST.

I will include it in the library sooner or later, but would like to make some extensive tests before publishing. I regret I do not have enough time available now, so let's keep the issue open ;)