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

Load included and related serializers in meta class #926

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

Merged
sliverc merged 15 commits into django-json-api:master from SafaAlfulaij:import-serializers-in-meta-class
Jul 18, 2021
Merged

Load included and related serializers in meta class #926

sliverc merged 15 commits into django-json-api:master from SafaAlfulaij:import-serializers-in-meta-class
Jul 18, 2021

Conversation

Copy link
Contributor

@SafaAlfulaij SafaAlfulaij commented Apr 18, 2021
edited by sliverc
Loading

Fixes #858

Description of the Change

As mentioned in the issue, this caches included_serializers and related_serializers in the dictionary to ease the process of retrieving in various places.
This approach is also used by DRF for binding fields: https://github.com/encode/django-rest-framework/blob/71e6c30034a1dd35a39ca74f86c371713e762c79/rest_framework/utils/serializer_helpers.py#L137

Checklist

  • PR only contains one change (considered splitting up PR)
  • unit-test (削除) added (削除ここまで) updated
  • documentation updated
  • CHANGELOG.md updated (only for user relevant changes)
  • author name in AUTHORS

Copy link

codecov bot commented Apr 18, 2021
edited
Loading

Codecov Report

Merging #926 (c863a3d) into master (684063b) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@ Coverage Diff @@
## master #926 +/- ##
=======================================
 Coverage 96.81% 96.82% 
=======================================
 Files 65 65 
 Lines 3894 3904 +10 
=======================================
+ Hits 3770 3780 +10 
 Misses 124 124 
Impacted Files Coverage Δ
rest_framework_json_api/relations.py 88.46% <100.00%> (ø)
rest_framework_json_api/renderers.py 90.15% <100.00%> (ø)
rest_framework_json_api/schemas/openapi.py 98.64% <100.00%> (+0.42%) ⬆️
tests/test_serializers.py 100.00% <100.00%> (ø)
example/utils.py 92.36% <0.00%> (-0.20%) ⬇️
example/views.py 94.21% <0.00%> (-0.08%) ⬇️
example/tests/test_serializers.py
example/serializers.py 89.14% <0.00%> (+1.06%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 684063b...c863a3d. Read the comment docs.

Copy link
Member

@sliverc sliverc left a comment
edited
Loading

Choose a reason for hiding this comment

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

Thanks for working on this. See my inline comments and do not forget to write a changelog entry.

Copy link
Contributor Author

Changes done.
But I'm not sure what to do with "self" and inline self-related serializers.

@SafaAlfulaij SafaAlfulaij marked this pull request as draft May 5, 2021 06:13
@SafaAlfulaij SafaAlfulaij marked this pull request as ready for review May 5, 2021 19:28
Copy link
Contributor Author

Ping?

Copy link
Member

@sliverc sliverc left a comment

Choose a reason for hiding this comment

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

I haven't forgotten about this PR but haven't really had time to look at it closely.

Seems some comments were not addressed but somehow through outdating were resolved by GitHub directly. So I moved those comment to the right code line.

Sorry if this has caused lots of notifications. The conversations which are still open are the issues which still need to be addressed. Thanks.

Copy link
Contributor Author

I'm sorry but I can't work on this anymore. I tried an approach where I set included_serializers and related_serializers to None if not provided, but it resulted in a bit more complicated code, you'll find it before applying the commit "Simplify caching included serializers".

Copy link
Member

sliverc commented Jul 18, 2021

@SafaAlfulaij Thanks for having worked on this. I made the last minor changes and this PR should be ready now and be merged once CI is green.

SafaAlfulaij reacted with thumbs up emoji

@sliverc sliverc changed the title (削除) Cache included and related serializers (削除ここまで) (追記) Load included and related serializers in meta class (追記ここまで) Jul 18, 2021
@sliverc sliverc merged commit ca627a9 into django-json-api:master Jul 18, 2021
Copy link
Contributor

jarekwg commented Nov 3, 2021

@sliverc this is a pretty neat performance boost, what's the plan for the next release?

Copy link
Member

sliverc commented Nov 5, 2021
edited
Loading

@jarekwg I would not overestimate this change in terms of performance because it's just few imports less. This is mainly a API cleanup so included serializers can be simply retrieved by serializer.included_serializers instead of a utility method.
In terms of next release I assume we will do one once Django 4.0 is released (according to release notes expected in December).

auvipy and jarekwg reacted with thumbs up emoji

Copy link
Contributor

auvipy commented Nov 5, 2021

besides django 4.0 compat new release is needed in drf as well.

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

@sliverc sliverc sliverc approved these changes

+1 more reviewer

@auvipy auvipy auvipy left review comments

Reviewers whose approvals may not affect merge requirements
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

included_serializers should be imported in meta class

AltStyle によって変換されたページ (->オリジナル) /