Skip to content

Conversation

@bmampaey
Copy link

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.

… view in OrderingFilter backend instead of calling the view's get_serializer_class method
@jpadilla jpadilla added this to the 3.3.3 Release milestone Feb 25, 2016
@jpadilla
Copy link
Contributor

@bmampaey Thanks! LGTM 👍

@xordoquy
Copy link
Contributor

Need to figure out why the assertion is raised.

@kevin-brown
Copy link
Contributor

@xordoquy My guess is during the check for serializer_class.

@jpadilla
Copy link
Contributor

Yep yep what @kevin-brown said

@xordoquy
Copy link
Contributor

xordoquy commented Mar 1, 2016

ok, let me rephrase this. I'm a bit reluctant to leave the assertion error assume it'll only be the get_serializer_class configuration error.
On the other hand, I don't have better options yet.

@jpadilla
Copy link
Contributor

jpadilla commented Mar 1, 2016

@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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

@kmwenja
Copy link
Contributor

kmwenja commented May 28, 2016

@jpadilla I totally missed this when I updated #3487. But I didn't cover the (AssertionError, AttributeError) case.

@lovelydinosaur lovelydinosaur modified the milestones: 3.3.4 Release, 3.4.0 Release Jun 1, 2016
@lovelydinosaur lovelydinosaur changed the title Fixed issue 3957 where serializer_class wass accessed directly on the… OrderingFilter should call get_serializer_class() to determine default fields. Jun 1, 2016
@lovelydinosaur
Copy link
Contributor

Thanks folks - now all resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants