-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Return None values as None in ListSerializer.to_representation #9386
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
base: master
Are you sure you want to change the base?
Conversation
@@ -711,7 +711,7 @@ def to_representation(self, data): | |||
iterable = data.all() if isinstance(data, models.manager.BaseManager) else data | |||
|
|||
return [ | |||
self.child.to_representation(item) for item in iterable | |||
self.child.to_representation(item) if item is not None else None for item in iterable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we will need extensive tests for changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
absolutely. I didn't expect this to be merged as-is, just want to start the conversation.
In terms of tests, what kind of test do we want? I'm thinking just adding new tests for the new behavior.
I think the tricky thing is that we don't know if the current behavior is relied upon, because there's no existing tests for that, do you know if there's a way to get that infromation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please refer to this comment #9386 (comment)
Since the use case is already handled in What is the point of using |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Description
I recently encountered some unexpected behavior when using ListSerializer when there are
None
values in the list.Here's a snippet that describes the issue and provides a way to reproduce it:
traceback:
Another thing to note is that
ListField
already handles it properly (in #4118 ), in fact I'm just copying what's been done toListField
toListSerializer
.So I think there are two issues that kinda throws me off:
.data
attribute.ListField