-
Notifications
You must be signed in to change notification settings - Fork 0
Patching {"data": null} on To-One relationship fails #46
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
Comments
@tpansino and I already discussed this IRL, but I just wanted to leave a comment and mention that we have run into this issue in https://github.com/Vacasa/housekeeping-web, where I cannot clear an existing to-one relationship by sending Technically, we can work around this by making a DELETE request on the relationship from the opposite direction, but that is far from ideal, and is a bit confusing. If it's possible to make any progress on this issue, it would be extremely helpful, because I imagine we will continue running into this as the API grows and we consume more endpoints. |
@gargrave For completeness - can you also try Edit: Whoops, I meant |
@tpansino Hopefully I am understanding correctly--the other direction is a to-many, so rather than taking If I completely missed your point, feel free to give me a shout. 👍 |
Yep, that's correct, sorry for the confusion and thanks for checking. |
After some digging, I've determined that this is a regression that happened during #29, specifically this line: https://github.com/Vacasa/drf-jsonapi/pull/32/files#diff-9a2180fee48df47db205fc59be17fa76L380 By removing the A better place to put this line would be right after the |
I just realized I'm conflating two unrelated issues here. The original reason I opened this Issue was because So these are related issues, but have different fixes. I'll open another issue. |
Needs to also be fixed on |
Describe the bug
See https://jsonapi.org/format/#crud-updating-to-one-relationships
Specifically, this case:
Isn't working properly. The code seems to be expecting the
data:
object to have atype
, so I think it needs to be updated to skip this check in the event we're patching a To-One relationship and the passed value isnull
. (The relationshipForeignKey
orOneToOneField
would also need to be nullable, but I have a feeling that's beyond the scope of what this package cares to check and is probably handled by Django at a lower level. Wouldn't hurt to test though to be sure...)To Reproduce
Define two models, one with a
ForeignKey
linking it to the other, and two corresponding endpoints with a relationship endpoint between the resources. Attempt toPATCH {"data": null}
on the To-One side of the relationship endpoint, observe an Exception is thrown.Expected behavior
The response should be a
204 No Content
code with the relationship successfully nullified.The text was updated successfully, but these errors were encountered: