Skip to content
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

One to Many objects updated but changes not reflected in the response when using prefetch_related #4551

Closed
gkpo opened this issue Oct 10, 2016 · 2 comments

Comments

@gkpo
Copy link

gkpo commented Oct 10, 2016

For the sake of simplicity, I'll be talking about Posts and Comments event though my models are different ones. This could be a duplicate of #1556, but it's closed and is about an outdated version of DRF.

Steps to reproduce

I created a PostViewSet and redefined the get_queryset method.

def get_queryset(self):
    queryset = Post.objects.prefetch_related('comments')
    return queryset

I'm trying to update the full Post object. For this I send a PUT request containing the post with its comments. I had to redefine the update method in the serializer to handle nested comments.

Expected behavior

The new comments are added to the post, the updated post is served back in the http response. With all updated fields, and updated comments.

Actual behavior

The new comments are indeed added to the post, but the returned item in the http response is the one BEFORE it was updated. Removing the prefetch_related solves the issue but I need it.

@xordoquy
Copy link
Collaborator

It's rather a duplicate of #2442.
Using prefetch requires the developer to override the returned value.

@tomchristie
Copy link
Member

Bumped the priority of #2442

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

No branches or pull requests

3 participants