-
-
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
should required
option be valid for output?
#2237
Comments
There's an explanation in the release notes about how |
@xordoquy |
@Catstyle Indeed, my bad. Would it be possible to have the stack traces for both points ? |
sure, this time we do it simply
|
updated
|
The 'required' option indicates if the input is required. Not which attributes are expected to exist on outputting the representation.
|
Indeed. It doesn't. It's possible that we could decide that simply returning |
i'd prefer {}, since it will reduce the output :) |
So I'd probably recommend a new base serializer class with an overridden For most of our users having a field that doesn't correspond to an attribute in the object is due to an application error. The softer mongodb style where fields may simply not exist isn't our standard case and it's easy enough to deal with by using a slightly modified base case (eg catch those attribute errors). However it would still be helpful to know what the 2.x behavior was here. Ie was it Could still be open to making some changes here but probably not what we want for the general case. |
pip install djangorestframework==2.4.4 -U
sure, i can do some compatible changes, just like you recommend |
Seems more by accident of implementation than by design. 2.x will use |
required
option be valid for output?
Okay, so if you need |
We can re-assess our guidance on this and/or our error messaging for this if it comes up again. |
i had upgraded from 2.4.4 to 3.0, and fix some incompatable things, but still i encountered some troubles
assumed we have a Serializer like this:
in my views i called
then, i got errors
1, TypeError: 'builtin_function_or_method' object is not iterableafter some tracing, i found that
fields.py:get_attribute
handling the dict after getattr, but unfortunately i got key name the same withdict.items
method name, so i think we should check__getitem__
value first then thegetattr
valuefixed 81d0b74
2, AttributeError: 'dict' object has no attribute 'bar'
after i fixed above error, i ran into another error, it seems that
required=False
doesn't workit started from serializer.data -> serializer.to_representation, and iterate all field.get_attribute(instance)
so should we pass field.required to get_attribute and return None if required is False?
The text was updated successfully, but these errors were encountered: