Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7k
Use get_serializer_class in ordering filter#3487
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Use get_serializer_class in ordering filter#3487
Uh oh!
There was an error while loading.Please reload this page.
Conversation
tests/test_filters.py Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Do you know why it doesn't ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
@xordoquy Sorry, I realized that theget_serializer_class method actually has its own assert to check forserializer_class:https://github.com/tomchristie/django-rest-framework/blob/master/rest_framework/generics.py#L123.
On that note, is it better to get the error fromget_serializer_class (AssertionError) or fromremove_invalid_fields (ImproperlyConfigured)? I can rewrite the patch to either catch theAssertionError inget_serializer_class or let it pass right up.
kmwenja commentedOct 9, 2015
@xordoquy I preferred raising |
kmwenja commentedOct 9, 2015
@xordoquy would it be presumptuous to update the docs at this point? |
xordoquy commentedOct 9, 2015
We'll take some time to review it first. |
OrderingFilter backend checks whether a view specifies anordering fields or serializer_class attribute. Views can howeveroverride get_serializer_class to determine the serializer_classbut the OrderingFilter doesn't catch this. This patch fixes that.
just checking that the ImproperlyConfigured error is raised ifordering_fields, serializer_class and get_serializer_class arenot provided in the view.
get_serializer_class raises an AssertionError if no serializer_classis found (either as a class attribute or from an overriding method).This commit catches it and raises ImproperlyConfigured instead.
c655de2 tobf498b2Comparecodecov-io commentedMay 26, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Current coverage is91.43%@@ master #3487 diff @@======================================= Files 51 49 -2 Lines 5476 5356 -120 Methods 0 0 Branches 0 0 =======================================- Hits 5005 4897 -108+ Misses 471 459 -12 Partials 0 0
|
kmwenja commentedMay 26, 2016
@xordoquy Updated the PR against master. Apologies for the lack of love. |
lovelydinosaur commentedMay 26, 2016
Perfectly reasonable, yup. Thanks! |
OrderingFilterbackend checks whether a view specifies anordering_fieldsorserializer_classattribute. Views can howeveroverride
get_serializer_classto determine the serializer classbut the
OrderingFilterdoesn't catch this. This patch fixes that.Here's an example of a view that would benefit from this patch:
This would formerly raise an
ImproperlyConfigurederror.