Skip to content

Add relationships support for pointers in errors #986

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
merged 4 commits into from
Oct 7, 2021

Conversation

mehdy
Copy link
Contributor

@mehdy mehdy commented Oct 3, 2021

Fixes #413

Description of the Change

When formatting DRF errors, use relationships in the pointer when the field is actually a relationship.

Checklist

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

@mehdy
Copy link
Contributor Author

mehdy commented Oct 3, 2021

@sliverc This is my draft attempt at solving the problem. I was wondering if you could give me some hints on whether I'm headed in the right direction or not?

@codecov
Copy link

codecov bot commented Oct 3, 2021

Codecov Report

Merging #986 (24de3fa) into master (0816192) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #986      +/-   ##
==========================================
+ Coverage   96.83%   96.84%   +0.01%     
==========================================
  Files          65       65              
  Lines        3914     3929      +15     
==========================================
+ Hits         3790     3805      +15     
  Misses        124      124              
Impacted Files Coverage Δ
example/tests/snapshots/snap_test_errors.py 100.00% <100.00%> (ø)
example/tests/test_errors.py 100.00% <100.00%> (ø)
rest_framework_json_api/renderers.py 90.15% <100.00%> (ø)
example/utils.py 92.67% <0.00%> (+0.30%) ⬆️

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 0816192...24de3fa. Read the comment docs.

@sliverc
Copy link
Member

sliverc commented Oct 3, 2021

Yes you are on the right track. included_serializers is optional though so not the right way to determine whether a field is a relationship. See here how an attribute is distinguished from relationship in the renderer.

@mehdy
Copy link
Contributor Author

mehdy commented Oct 3, 2021

@sliverc Great! Thanks!

@mehdy mehdy changed the title WIP: Add relationships support for pointers in errors Add relationships support for pointers in errors Oct 3, 2021
@mehdy
Copy link
Contributor Author

mehdy commented Oct 3, 2021

@sliverc
I think this is ready for review.
Just let me know if I should add it to CHANGELOG.md and/or the docs.

@mehdy
Copy link
Contributor Author

mehdy commented Oct 5, 2021

@sliverc I couldn't understand why codecov is failing. Should I do something?

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.

Thanks for working on this. Please see my inline comments.

@mehdy
Copy link
Contributor Author

mehdy commented Oct 6, 2021

@sliverc Resolved all the issues you mentioned.

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.

This PR is shaping up nicely. See some small comments inline.

@mehdy
Copy link
Contributor Author

mehdy commented Oct 6, 2021

@sliverc Done as well. Thanks for the tips.

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.

Thanks for the changes. Somewhat one of my comment got swallowed (maybe had to many tabs open... 😄 ) See last comment, also rebase to current master and then this PR is good to merge.

@sliverc
Copy link
Member

sliverc commented Oct 6, 2021

and totally forgot please also add a changelog entry.

@mehdy
Copy link
Contributor Author

mehdy commented Oct 6, 2021

@sliverc I think we're good to go :D

Signed-off-by: Mehdy Khoshnoody <[email protected]>
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.

Thanks for the changes and your time putting into making this work. Very appreciated.

It seems that you (your IDE?) autoformatted the changelog markdown file (I guess with prettier?). There were quite a few changes... I reverted those to make this PR ready. But certainly something to think about whether as DJA we want to autoformat md files but I guess part of another discussion.

Thanks again.

@sliverc sliverc merged commit ee679ee into django-json-api:master Oct 7, 2021
@mehdy
Copy link
Contributor Author

mehdy commented Oct 7, 2021

@sliverc You're very welcome!
Sorry about the autoformat. Thanks for taking care of it though. :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error pointer always refers to the attributes
3 participants