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

Ignoring none field on serialization if it is not required. #64

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

thgbarros
Copy link

If the class had a default value defined with none, the serializer class was serialize the field with
{field: None}.

class ASerializer(Serializer):
   a = Field(required=False)   

class AObject:
   def __init__(a = None):
     self.a = a

print(ASerializer(AObject()).data) 
output = {'a': None} 

Now:

class ASerializer(Serializer):
   a = Field(required=False)

class AObject:
   def __init__(a = None):
     self.a = a

print(ASerializer(AObject()).data) 
output = {}  

but if the field is required, the output have a field none.

class ASerializer(Serializer):
   a = Field()

class AObject:
   def __init__(a = None):
     self.a = a

print(ASerializer(AObject()).data) 
output = {'a': None}  

@coveralls
Copy link

coveralls commented Mar 15, 2018

Coverage Status

Coverage decreased (-0.8%) to 99.174% when pulling db79da7 on thgbarros:master into 56e5a27 on clarkduvall:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.8%) to 99.174% when pulling db79da7 on thgbarros:master into 56e5a27 on clarkduvall:master.

@clarkduvall
Copy link
Owner

This is actually the expected behavior, for more info you can check out #56 and the fix in #57. To have the field removed from the output, it should not be present at all in the input.

Thanks!

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

Successfully merging this pull request may close these issues.

4 participants