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

Serializer data property does not update on PUT and displays initial values #2593

Closed
tobiaz opened this issue Feb 24, 2015 · 2 comments
Closed

Comments

@tobiaz
Copy link

tobiaz commented Feb 24, 2015

When doing the following:

def put(self, request, pk, format=None):
        event = self.get_event(request, pk)
        event_serializer = CalendarEventSerializer(event, data=request.data, partial=True)

        if event_serializer.is_valid():
            event_serializer.save()
            return Response(event_serializer.data)

Reponse returns dict that does not show updated data. I had to do this for a workaround to make sure data is updated.

event_serializer._data = event_serializer.to_representation(event_serializer.instance)

I've tried tracing down the issue but can't seem to find it. The _date seems to be using is_initial values as everything else is correct within the serializer instance.

@carltongibson
Copy link
Collaborator

I'm going to close this for now as I suspect you're accessing data somewhere during validation — or such. The bottom line will be "Don't do this". data is populated on demand so if you don't call it early you'll get the post-save values you're after.

See: #2532, #2276, #2289 and probably others for extended discussion of this topic.

If there's something not covered there please come back here with what we need to reproduce the issue — ideally a failing test case — and we can re-open.

@tobiaz
Copy link
Author

tobiaz commented Feb 24, 2015

Thank you for the feedback. You're correct, I was accessing data instead of initial data, apologies. As a side note: this project is one of the best I've ever used, thank you!!!

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

No branches or pull requests

2 participants