-
-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Applying distinct sometimes results in errors #19
Comments
Hi, |
I'm seeing the problem in both the provided example and in my own project. Before using distinct everything works, but when applying distinct things go awry. By playing around with things I did find that the reason rank works, but year doesn't is that rank is the first column called in the table. If I filter by distinct('year') and then set columns in the DataTable like this:
then I get a valid DataTable. Whatever field is distinct must be the first field called in the table. The I can use ColReorder to move the columns around as needed. The problem now is that while I get a table now, I can ONLY sort by the column that is distinct. Attempting to sort by any other column (using the table headers) returns ajax errors, both in the (modified) example project and in my own project. |
I seem to have found a solution, though I don't know why it works. If I change:
to:
... all works perfectly! Sorting, filtering, etc all work now. An extra query is required, but it's worth it. Still not sure why simply applying distinct fails to work properly, but I can live with this modification |
I'm using postgresql as my database.
The example works perfectly as-is. Additionally, if I change
to
or
everything works as expected. I get object instances with distinct rank or id.
But, if instead I set distinct to 'year', which just like rank is a PositiveIntegerField in the model:
...I run into problems. What's weird is that in the DRF API viewer, everything looks great. I get the expected resulting filtered queryset.
But the DataTable fails to load and gives an error:
When I use Chrome's inspector, it looks like DataTables is trying to load this URL:
...which results in an internal server error. Here's the entire resulting trace if I go to that url: https://pastebin.com/U8jbeXAA
The text was updated successfully, but these errors were encountered: