-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
possible bug with ordering (throws exception) #3390
Comments
Duplicate of #3324 Currently resolved in master. |
Sorry, but I don't think that issue is resolved. a) IMO there is something missing, because you check for valid_fields is None and valid_fields is "all", but you don't check for the actual defined fields. I'm happy to send a PR if you agree with the mentioned issues. If you don't agree, could you please explain how this is supposed to work? |
Reopening to re-review. First: Can you confirm that you see the same behaviour against master. |
I'll do some more tests and get back to you. I'm already having a patch which works well with our environment, but need to do a bit of cleanup. Just one question about the intended behaviour. Referring to the example above, I should be able to use |
Note: I'm able to reproduce the behaviour with master. Added a PR. |
Oaky I've had a chance to review this.
The expectation here is incorrect. Ordering fields don't get mapped via the serializer If you want custom behavior here you'll need to implement this independently - this is not the behavior we want in core. |
As an API user I would expect to be able to order the result based upon the fields provided in the result set. This means if I receive a result set similar to this one:
I would expect to be able to order via `ìd As in this case the
The API creator would have to explain the API user that the group field is a mapping to the category field and the user should use Therefore, I would ask you to re-open this issue. |
There's a strong case to make for the Ordering filter to allow explicit mappings between the incoming query parameter and the resulting filter that's applied, but implicit mappings between the filter and the serializer are not the answer. |
Can you please explain this |
@mr-stateradio the point is that the user would not have to deal with this. It'll just be the developer's work to create this mapping. |
^ Yes, although I'd say it more strongly than that - tight coupling between the ordering filter and serializer class is bad for more reasons than just Django's Models (eg. makes alternative third party serializers less viable) |
@xordoquy agreed, we don't wanna be tied to model things (but that's exactly what happens right now). |
@tomchristie The coupling between the ordering filter and the serializer class does not have to be tight or even exclusively. But it should allow the api developer to create an ordering filter for the serializer fields as well as for the model fields. Leave it to the developer to decide what he/she thinks works best for the api users. |
I'd far rather see us consider gradually deprecating 'all' behavior - having a coupled-to-the-serializer variation avail as third party package but not core. |
When I define ordering fields with my ModelViewSet ...
And my serializer has ...
I expect this ordering field to either work or be ignored. Currently, an exception is being returned ...
I tried to track this down and had to stop at filters.py, line 158. It seems that
remove_invalid_fields
always compares the defined ordering_fields to itself (maybe that´s intentional).https://github.com/tomchristie/django-rest-framework/blob/master/rest_framework/filters.py#L158
The text was updated successfully, but these errors were encountered: