HStore: This field may not be null. · Issue #5644 · encode/django-rest-framework (original) (raw)
Navigation Menu
- Explore
- Pricing
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Appearance settings
Description
Steps to reproduce
class Product(models.Model): title = CharField(max_length=512) attributes = HStoreField(null=True, blank=True)
class ProductSerializer(serializers.ModelSerializer): class Meta: model = Product fields = ('title', 'attributes')
Some try:
p = Product(title="foobar", attributes={'first': 'value', 'second': None}) p.save() # Save success. No error here!
Now, Let's try with Serializer
data = {"title": "foobar", "attributes": {"first": "value", "second": None}} q = ProductSerializer(data=data) q.is_valid() #> False q.errors #> {'attributes': ['This field may not be null.']}
Expected behavior
q
is valid
Actual behavior
As you can see, q
is invalid with an error {'attributes': ['This field may not be null.']}
.
When I remove "second": None
from attributes
. q
is valid