Skip to content

Patching {"data": <anything>} on To-One relationship fails #53

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

Open
tpansino opened this issue Apr 19, 2019 · 2 comments
Open

Patching {"data": <anything>} on To-One relationship fails #53

tpansino opened this issue Apr 19, 2019 · 2 comments

Comments

@tpansino
Copy link
Contributor

Describe the bug
This is REALLY similar to #46, but the fix is totally different...

See https://jsonapi.org/format/#crud-updating-to-one-relationships

Specifically, this case:

PATCH /articles/1/relationships/author HTTP/1.1
Content-Type: application/vnd.api+json
Accept: application/vnd.api+json

{
  "data": { "type": "people", "id": "12" }
}

Isn't working properly.

This is a regression created in #29 by removing this line: https://github.com/Vacasa/drf-jsonapi/pull/32/files#diff-9a2180fee48df47db205fc59be17fa76L380

Without that, the change to the To-One relationship never gets saved and committed to the database.

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 to PATCH the To-One direction of the relationship with a related resource. Observe no error, but the relationship does not change.

Expected behavior
The response should be a 204 No Content code with the relationship successfully changed.

@tpansino
Copy link
Contributor Author

I made a mistake in #54 which prevented models with multiple required To-One relationships from being saved to the DB. Resolved in #56 by putting the save() call in the right place.

@tpansino tpansino reopened this Apr 24, 2019
@tpansino
Copy link
Contributor Author

Just realized we still need to fix this for master, reopening.

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

No branches or pull requests

2 participants