-
-
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
Accessing serializer.data in a validate method shouldn't return stale data #2276
Comments
You certainly shouldn't be doing that, no. Not clear what the intention would be. |
Thanks for the quick reply. If you think of a reasonable way to protect On Monday, December 15, 2014, Tom Christie [email protected] wrote:
Cheers, Peter Schmidt |
Let's close it off for now - there might be further improvements we could make to restricting how the serializers can validly be called, but I can't see anything obvious at the moment. |
Opened #2289 to improve the constraints around this - eg raise a helpful error when this is attempted. |
Example test case I think illustrates the issue:
https://github.com/mathspace/django-rest-framework/compare/validation-race
If I call
self.data
inside aserializer.validate
, the existing stale instance data ends up cached onserializer._data
. The workaround that passed my tests was to accessserializer.instance
instead.Curious as to thoughts on this, e.g.
serializer.data
be accessible inside the validate methods, i.e. while the serializer is essentially still under construction?_data
cache be appropriately flushed so the test can pass?I would lean towards the former only because the
serializer.data
by being partly constructed could be quite misleading.The text was updated successfully, but these errors were encountered: