-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Patching a field on a model with a ManyToManyField removes the related objects #2829
Comments
Sorry to not be more help, but the issue needs to be more clearly outlined as it currently stands. |
This is actually the minimal test case that I can come up with, I tried testing the serializer itself with the model but couldn't reproduce it. It only happens when I have a updating view + serializer + model that I see this happen. I'm new to django so I'm not even sure where to decouple everything to debug this, since all I'm really doing is configuration (declaratively specifying the view/serializer/model). so I wasn't sure if I was configuring things correctly |
This is the test I ran against the serializer itself class TestSerializerForModelWithM2MField(TestCase):
def test_patch_many_to_many(self):
new_author_data = {
'name': 'pyeekwr'
}
test_author = Author.objects.create(**new_author_data)
new_stuff_data = {
'content': 'This is my content body',
'description': 'This is the description',
}
test_stuff = Stuff.objects.create(**new_stuff_data)
test_stuff.authors.add(test_author)
patch_data = {
'description': 'This is the new description',
}
serializer = StuffSerializer(test_stuff, data=patch_data, partial=True)
serializer.is_valid()
instance = serializer.save()
self.assertEqual(instance.description, patch_data['description'])
self.assertEqual(instance.authors.count(), 1) |
any suggestions on what test case I can build? I can do that if you''re able to tell me. |
This looks valid to me. Confirmation of reproducibility from anyone else would help us figure out if we should be prioritizing it, and if it's still valid. |
Assuming this is closed along with #2761 |
I am currently on drf 3.0
I am running into an issue where when I am trying to PATCH a field on a model with a ManyToManyField, the model serializer produces a deserialization where the related many to many relation gets removed, even though the field payload does not include the many to many field. Is this intended behavior? or am I configuring this incorrectly?
Test case
The text was updated successfully, but these errors were encountered: