-
Notifications
You must be signed in to change notification settings - Fork 299
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
Conversation
@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.
@sliverc Should I look at this now or wait until the test failures are resolved?
@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
55cd1ea
to
408427b
Compare
408427b
to
f3dd4a1
Compare
@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.
There was a problem hiding this 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!
Uh oh!
There was an error while loading. Please reload this page.
Fixes #488
Description of the Change
In case of a reverse one-to-one relationships
get_relation_instance
would swallowDoesNotExist
exception leading renderer to skip field. Such field instead should be rendered asnull
and never be skipped.Checklist
CHANGELOG.md
AUTHORS