Skip to content

HStore: This field may not be null. #5644

Closed
@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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions