Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Conversation

@kmwenja
Copy link
Contributor

OrderingFilter backend checks whether a view specifies an
ordering_fields orserializer_class attribute. Views can however
overrideget_serializer_class to determine the serializer class
but theOrderingFilter doesn't catch this. This patch fixes that.

Here's an example of a view that would benefit from this patch:

classMyView(generics.ListAPIView):queryset=MyModel.objects.all()filter_backends= (filters.OrderingFilter, )defget_serializer_class(self):returnMySerializer

This would formerly raise anImproperlyConfigured error.

Copy link
Contributor

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 ?

Copy link
ContributorAuthor

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.

@xordoquyxordoquy added this to the3.3.0 Release milestoneOct 9, 2015
@kmwenja
Copy link
ContributorAuthor

@xordoquy I preferred raisingImproperlyConfigured (since that was the initial intended purpose) but I can quickly change that.

@kmwenja
Copy link
ContributorAuthor

@xordoquy would it be presumptuous to update the docs at this point?

@xordoquy
Copy link
Contributor

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.
@kmwenjakmwenjaforce-pushed theuse-get-serializer-class-in-ordering-filter branch fromc655de2 tobf498b2CompareMay 26, 2016 05:38
@codecov-io
Copy link

codecov-io commentedMay 26, 2016
edited
Loading

Current coverage is91.43%

Merging#3487 intomaster will increase coverage by<.01%

@@             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

Powered byCodecov. Last updated by35ace2e...f341e14

@kmwenja
Copy link
ContributorAuthor

@xordoquy Updated the PR against master. Apologies for the lack of love.

@lovelydinosaurlovelydinosaur modified the milestones:3.3.4 Release,3.4.0 ReleaseMay 26, 2016
@lovelydinosaur
Copy link
Contributor

Perfectly reasonable, yup. Thanks!

@lovelydinosaurlovelydinosaur merged commit592eea9 intoencode:masterMay 26, 2016
@lovelydinosaurlovelydinosaur modified the milestones:3.3.4 Release,3.4.0 ReleaseJun 1, 2016
@kmwenjakmwenja deleted the use-get-serializer-class-in-ordering-filter branchAugust 6, 2018 10:44
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

3.4.0 Release

Development

Successfully merging this pull request may close these issues.

4 participants

@kmwenja@xordoquy@codecov-io@lovelydinosaur

[8]ページ先頭

©2009-2025 Movatter.jp