OrderingFilter should call get_serializer_class() to determine default fields.#3964
OrderingFilter should call get_serializer_class() to determine default fields.#3964bmampaey wants to merge 1 commit intoencode:masterfrom
OrderingFilter should call get_serializer_class() to determine default fields.#3964Conversation
… view in OrderingFilter backend instead of calling the view's get_serializer_class method
|
@bmampaey Thanks! LGTM 👍 |
|
Need to figure out why the assertion is raised. |
|
@xordoquy My guess is during the check for |
|
Yep yep what @kevin-brown said |
|
ok, let me rephrase this. I'm a bit reluctant to leave the assertion error assume it'll only be the |
|
@xordoquy I see what you mean, but I don't think we're not even initializing a serializer in there, so I'm not sure from where else we could get thrown an assertion error at that point. |
| if serializer_class is None: | ||
| try: | ||
| serializer_class = view.get_serializer_class() | ||
| except AssertionError: |
There was a problem hiding this comment.
Might be better to use except (AssertionError, AttributeError) here, in case get_serializer_class does not exist on the view (eg using basic APIView, rather than the generic classes)
OrderingFilter should call get_serializer_class() to determine default fields.
|
Thanks folks - now all resolved. |
refs #3957
I made the proposed change
Because the default get_serializer_class method of GenericAPIView throw an Assertion error if there is no serializer_class defined on the view, I made a try except block that catches the exception and return the message as defined previously. I don't know if that is the correct idea.
I also added 3 tests for this fix.