Skip to content

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