-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Raise error when calling serializer.data
after serializer.is_valid
fails
#6421
Comments
It doesn’t make sense to call .data on an invalid serializer |
I guess we may want to consider raising an explicit error for this usage. |
@tomchristie yes, this sounds sensible. If it's not intended practice to access that attribute on an invalid serializer, it should explicitly warn the engineer. Currently, it looks like a bug since accessing the same attribute on a serializer where |
@tomchristie Do you mean it should raise an error when |
Yes
most probably, otherwise it wouldn't be able to serialize data any more.
|
Ok, I am working on it. What about |
Current behavior feels ok to me: |
serializer.data
after serializer.is_valid
fails
Is there an update on this issue? I think this scenario should result in exception because |
Closing as per #6528. I think having slightly under defined behaviour isn't necessarily ideal, but isn't awful either. |
Checklist
master
branch of Django REST framework.Steps to reproduce
I have included the steps I took below via a terminal. This seems to affect both standard serializers and model serializers.
Expected behavior
I would expect that when calling the
data
attribute on the "many" serializer that the input data would be returned, so in the example above, I would expect the following output fromdata
[{}, {}, {}]
Actual behavior
Actual behaviour raises the exception included above. It seems that the
get_attribute
method naively always assumes that an attribute will be present indata
.I would really appreciate your thoughts on this.
Thanks for this amazing framework, big fan!! :)
The text was updated successfully, but these errors were encountered: