HStore: This field may not be null. · Issue #5644 · encode/django-rest-framework (original) (raw)

Skip to content

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

Appearance settings

@dungdm93

Description

@dungdm93

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