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

Do not skip empty one-to-one relationships #526

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
n2ygk merged 1 commit into django-json-api:master from sliverc:null_relationships
Dec 6, 2018

Conversation

Copy link
Member

@sliverc sliverc commented Dec 4, 2018
edited
Loading

Fixes #488

Description of the Change

In case of a reverse one-to-one relationships get_relation_instance would swallow DoesNotExist exception leading renderer to skip field. Such field instead should be rendered as null and never be skipped.

Checklist

  • PR only contains one change (considered splitting up PR)
  • unit-test added
  • documentation updated
  • changelog entry added to CHANGELOG.md
  • author name in AUTHORS

@sliverc sliverc requested a review from n2ygk December 4, 2018 13:40
Copy link
Member Author

sliverc commented Dec 4, 2018

@n2ygk
Changing renderer always has some risks, but making it better conform to JSON api there is no way around it 😄

However good testing is always a good thing. I have therefore test run this in the projects I am using DJA and it turned out green. If you have any projects to test run it in that would be great too, to lower the barrier that there is a regression in this PR.

Copy link
Contributor

n2ygk commented Dec 4, 2018

@sliverc Should I look at this now or wait until the test failures are resolved?

Copy link
Contributor

n2ygk commented Dec 4, 2018
edited
Loading

@sliverc: I'm confused as this was already working per the spec for me. I've compared

git+https://github.com/django-json-api/django-rest-framework-json-api.git@8c075d0 vs
git+https://github.com/sliverc/django-rest-framework-json-api.git@null_relationships

And both return an empty list for a to-many relationships and null for a to-one.

Is this only for HyperlinkedIdentityField? I don't use that in my code.

PS: My sample code is here: https://github.com/columbia-it/django-jsonapi-training

@sliverc sliverc changed the title (削除) Render empty resource linkages as specified (削除ここまで) (追記) Do not skip empty one-to-one relationships (追記ここまで) Dec 5, 2018
Copy link
Member Author

sliverc commented Dec 5, 2018

@n2ygk
It's just in corner cases where a relationship is not rendered but skipped. It is basically only when utils.get_relation_instance cannot resolve to a relation instance.
The only known case where utils.get_relation_instance cannot resolve is with a reverse OneToOneField leading to a DoesNotExist exception.

When thinking about it again it is properly better just to address this OneToOneField issue which is known and do not touch the other only hypothetical errors which might actually never happen.

Hence I have simplified this PR and clarified it in comment and changelog. Best have a look again.

Copy link
Contributor

@n2ygk n2ygk left a comment

Choose a reason for hiding this comment

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

I create a NULLable OneToOneField model in my test app and was able to reproduce this and confirm the functionality. Thanks for this fix!

@n2ygk n2ygk merged commit e5bea80 into django-json-api:master Dec 6, 2018
@sliverc sliverc deleted the null_relationships branch December 7, 2018 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@n2ygk n2ygk n2ygk approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants

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