-
Notifications
You must be signed in to change notification settings - Fork 301
Issues with RelationshipView PATCH endpoint (to-many) #784
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
Thanks for reporting and your very detailed bug report. 👍 Deleting with an empty list actually has never been implemented (see #244) but it seems as a side product of #242 it is now worse. And when quickly looking at the code your first issue also makes sense why it occurs but it should not... RelationshipView could need some love... pull request are very welcome. |
rohithpr
added a commit
to rohithpr/django-rest-framework-json-api
that referenced
this issue
May 14, 2020
…hem during PATCH Calling PATCH on an M2M RelationshipView when there were already some relationships was breaking. This was because the related objects were being deleted instead of just clearing the relationship and starting afresh.
5 tasks
rohithpr
added a commit
to rohithpr/django-rest-framework-json-api
that referenced
this issue
May 14, 2020
…hem during PATCH Calling PATCH on an M2M RelationshipView when there were already some relationships was breaking. This was because the related objects were being deleted instead of just clearing the relationship and starting afresh.
rohithpr
added a commit
to rohithpr/django-rest-framework-json-api
that referenced
this issue
Jun 10, 2020
…hem during PATCH Calling PATCH on an M2M RelationshipView when there were already some relationships was breaking. This was because the related objects were being deleted instead of just clearing the relationship and starting afresh.
rohithpr
added a commit
to rohithpr/django-rest-framework-json-api
that referenced
this issue
Jun 10, 2020
…hem during PATCH Calling PATCH on an M2M RelationshipView when there were already some relationships was breaking. This was because the related objects were being deleted instead of just clearing the relationship and starting afresh.
sliverc
pushed a commit
to rohithpr/django-rest-framework-json-api
that referenced
this issue
Jun 13, 2020
…hem during PATCH Calling PATCH on an M2M RelationshipView when there were already some relationships was breaking. This was because the related objects were being deleted instead of just clearing the relationship and starting afresh.
sliverc
added a commit
that referenced
this issue
Jun 13, 2020
…TCH (#788) Fixes #784 Fixes #244 Co-authored-by: Oliver Sauder <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi folks, I think I run into two unexpected behaviors with RelationshipView's PATCH endpoint when the relationship is to-many. I'm fairly new on JSON:API, so in case I'm doing anything wrong, please let me know!
The 1st issue is that, the endpoint throws an IntegrityError when PATCHing the endpoint with the same object as retrieved.
The 2nd issue is that, the endpoint incorrectly deletes the actual related object when PATCHing with an empty list, while I only expect it to delete the relationship from the m2m table.
The POST and DELETE endpoints were working as expected.
Steps to replicate
I was able to replicate it with a minimal example https://github.com/lingxiaoyang/dja-patch-issue on Python 3.8 and the latest stable Django, DRF and both stable and master DJA.
To replicate, please clone my test repo and run:
In the shell, create the base objects:
Proof
The endpoint to test is either:
http://localhost:8000/articles/1/relationships/tags/ or
http://localhost:8000/tags/1/relationships/articles/
First, GET the relationship endpoint and verify the data is empty
Then, PATCH the relationship endpoint to add a relationship
Now, PATCH the relationship endpoint again with same data. The 500 IntegrityError is returned while it should make no changes to the existing relationship.
Then, PATCH the endpoint with empty data. It says the relationship is cleared.
However, the related object itself was just incorrectly deleted. The database query returns nothing.
The text was updated successfully, but these errors were encountered: