Skip to content

Instantly share code, notes, and snippets.

@dz0
Last active December 1, 2018 21:35
Show Gist options
  • Select an option

  • Save dz0/1145541c956389a4a7c07647cac760b7 to your computer and use it in GitHub Desktop.

Select an option

Save dz0/1145541c956389a4a7c07647cac760b7 to your computer and use it in GitHub Desktop.
DRF validate None on BooleanField serialization
from rest_framework.serializers import Serializer, BooleanField
# BooleanField.FALSE_VALUES.add(None) # does not help
class S(Serializer):
bf = BooleanField(required=False, read_only=True)
class example:
bf = None # I expect it to become **False**
s = S(instance=example)
assert s.data['bf'] == False # Fails, because {'bf': None}
# seems like related https://github.com/encode/django-rest-framework/issues/2299
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment